From 013bdd48d07cd7053a5ab558e7840cb7ef02dfd2 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sun, 27 Nov 2022 22:19:06 +0300 Subject: [PATCH] sendlink-template-patch --- src/components/Nav/AuthModal/ForgotPasswordForm.tsx | 2 +- src/components/Nav/AuthModal/LoginForm.tsx | 2 +- src/graphql/mutation/auth-send-link.ts | 4 ++-- src/stores/auth.ts | 12 ++++++++++-- src/utils/apiClient.ts | 6 ++++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx index 6a92582b..a20eeac3 100644 --- a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx +++ b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx @@ -54,7 +54,7 @@ export const ForgotPasswordForm = () => { setIsSubmitting(true) try { - await signSendLink({ email: email(), lang: locale() }) + await signSendLink({ email: email(), lang: locale(), template: 'forgot_password' }) } catch (error) { if (error instanceof ApiError && error.code === 'user_not_found') { setIsUserNotFound(true) diff --git a/src/components/Nav/AuthModal/LoginForm.tsx b/src/components/Nav/AuthModal/LoginForm.tsx index 89f98d66..68922c74 100644 --- a/src/components/Nav/AuthModal/LoginForm.tsx +++ b/src/components/Nav/AuthModal/LoginForm.tsx @@ -50,7 +50,7 @@ export const LoginForm = () => { setIsEmailNotConfirmed(false) setSubmitError('') setIsLinkSent(true) - const result = await signSendLink({ email: email(), lang: locale() }) + const result = await signSendLink({ email: email(), lang: locale(), template: 'email_confirmation' }) if (result.error) setSubmitError(result.error) } diff --git a/src/graphql/mutation/auth-send-link.ts b/src/graphql/mutation/auth-send-link.ts index f03c9378..3d8e8b6b 100644 --- a/src/graphql/mutation/auth-send-link.ts +++ b/src/graphql/mutation/auth-send-link.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - mutation SendLinkQuery($email: String!, $lang: String) { - sendLink(email: $email, lang: $lang) { + mutation SendLinkQuery($email: String!, $lang: String, $template: String) { + sendLink(email: $email, lang: $lang, template: $template) { error } } diff --git a/src/stores/auth.ts b/src/stores/auth.ts index b92814fa..defc4783 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -16,6 +16,14 @@ export const register = async ({ }) } -export const signSendLink = async ({ email, lang }: { email: string; lang: string }) => { - return await apiClient.authSendLink({ email, lang }) +export const signSendLink = async ({ + email, + lang, + template +}: { + email: string + lang: string + template: string +}) => { + return await apiClient.authSendLink({ email, lang, template }) } diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 602eb095..e1fbbb96 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -112,9 +112,11 @@ export const apiClient = { const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise() return response.data.isEmailUsed }, - authSendLink: async ({ email, lang }) => { + authSendLink: async ({ email, lang, template }) => { // send link with code on email - const response = await publicGraphQLClient.mutation(authSendLinkMutation, { email, lang }).toPromise() + const response = await publicGraphQLClient + .mutation(authSendLinkMutation, { email, lang, template }) + .toPromise() if (response.error) { if (response.error.message === '[GraphQL] User not found') {