The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/views/admin/users/hooks/useSendWelcomeEmailMutation.ts

29 lines
1017 B

import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import type { UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
type useSendWelcomeEmailMutationProps = {
email: string | undefined;
};
export const useSendWelcomeEmailMutation = (): UseMutationResult<null, Error, useSendWelcomeEmailMutationProps> => {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const sendWelcomeEmail = useEndpoint('POST', '/v1/users.sendWelcomeEmail');
return useMutation({
mutationFn: async ({ email }) => {
if (!email) {
dispatchToastMessage({ type: 'error', message: t('Welcome_email_failed') });
return null;
}
return sendWelcomeEmail({ email });
},
onSuccess: () => dispatchToastMessage({ type: 'success', message: t('Welcome_email_resent') }),
onError: (error) => dispatchToastMessage({ type: 'error', message: error }),
});
};