/**
* @file
* File : emailApiSlice.js\
* Defines API endpoints related to email operations using RTK Query.
* Extends the base API slice with additional email-related endpoints.
*
* @author Pierre-Yves Léglise <contact@axialdata.net>
* @name emailApiSlice
*/
import { apiSlice } from './apiSlice'
export const emailApiSlice = apiSlice.injectEndpoints({
/**
* Injects additional email-related endpoints into the base API slice.
* Defines endpoints for resending email and handling forgot password requests.
*
* @function
* @author Pierre-Yves Léglise <contact@axialdata.net>
* @param {Object} builder - RTK Query endpoints builder.
* @example
* const { useResendEmailMutation, useForgotPasswordMutation } = emailApiSlice
* @returns {Object} Object containing email-related endpoint definitions.
*/
endpoints: (builder) => ({
/**
* Endpoint for resending an email with a new link.
* Sends a POST request to the `/email/new-link` endpoint with provided credentials.
*
* @method
* @author Pierre-Yves Léglise <contact@axialdata.net>
* @name resendEmail
* @param {Object} credentials - User credentials needed to resend the email.
* @example
* const result = await resendEmail({ email: 'example@example.com' })
* @returns {Object} Result of the API request.
*/
resendEmail: builder.mutation({
query: (credentials) => ({
url: '/email/new-link',
method: 'post',
data: { ...credentials },
overrideExisting: true,
}),
keepUnusedDataFor: 0,
}),
/**
* Endpoint for handling forgot password requests.
* Sends a PATCH request to the `/email/password-lost` endpoint with provided credentials.
*
* @category ApiSlice
* @function
* @author Pierre-Yves Léglise <contact@axialdata.net>
* @name forgotPassword
* @param {Object} credentials - User credentials needed to process the forgot password request.
* @example
* const result = await forgotPassword({ email: 'example@example.com' })
* @returns {Object} Result of the API request.
*/
forgotPassword: builder.mutation({
query: (credentials) => ({
url: '/email/password-lost',
method: 'patch',
data: { ...credentials },
overrideExisting: true,
}),
keepUnusedDataFor: 0,
}),
}),
overrideExisting: true,
})
/**
* Hooks for interacting with the email-related endpoints.
*
* @typedef {Object} Hooks
* @author Pierre-Yves Léglise <contact@axialdata.net>
* @property {Function} useResendEmailMutation - Hook to trigger the resendEmail mutation.
* @property {Function} useForgotPasswordMutation - Hook to trigger the forgotPassword mutation.
* @example
* const { useResendEmailMutation, useForgotPasswordMutation } = emailApiSlice
* @returns {Object} Object containing email-related hook definitions.
*/
export const { useResendEmailMutation, useForgotPasswordMutation } =
emailApiSlice