diff --git a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx index fcb8777a..3987e40b 100644 --- a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx +++ b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx @@ -7,7 +7,8 @@ import { useRouter } from '../../../stores/router' import { email, setEmail } from './sharedLogic' import type { AuthModalSearchParams } from './types' import { isValidEmail } from './validators' -import { ApiError } from '../../../utils/apiClient' +import { signSendLink } from '../../../stores/auth' +import { locale } from '../../../stores/ui' type FormFields = { email: string @@ -51,7 +52,8 @@ export const ForgotPasswordForm = () => { setIsSubmitting(true) try { - // TODO: send mail with link to new password form + setSubmitError('') + signSendLink({ email: email(), lang: locale() }) } catch (error) { setSubmitError(error.message) } finally { diff --git a/src/components/Nav/AuthModal/LoginForm.tsx b/src/components/Nav/AuthModal/LoginForm.tsx index 115ee075..6989768c 100644 --- a/src/components/Nav/AuthModal/LoginForm.tsx +++ b/src/components/Nav/AuthModal/LoginForm.tsx @@ -10,6 +10,7 @@ import { isValidEmail } from './validators' import { email, setEmail } from './sharedLogic' import { useRouter } from '../../../stores/router' import type { AuthModalSearchParams } from './types' +import { hideModal, locale } from '../../../stores/ui' type FormFields = { email: string @@ -37,6 +38,14 @@ export const LoginForm = () => { setPassword(newPassword) } + const handleSendLinkAgainClick = (event: Event) => { + event.preventDefault() + setIsEmailNotConfirmed(false) + setSubmitError('') + setIsLinkSent(true) + signSendLink({ email: email(), lang: locale() }) + } + const handleSubmit = async (event: Event) => { event.preventDefault() diff --git a/src/graphql/mutation/auth-send-link.ts b/src/graphql/mutation/auth-send-link.ts index 66df4214..f03c9378 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` - query SendLinkQuery($email: String!) { - sendLink(email: $email) { + mutation SendLinkQuery($email: String!, $lang: String) { + sendLink(email: $email, lang: $lang) { error } } diff --git a/src/stores/auth.ts b/src/stores/auth.ts index edbc2b59..051e5125 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -54,9 +54,8 @@ export const register = async ({ }) } -export const signSendLink = async (params) => { - await apiClient.authSendLink(params) // { email } - resetToken() +export const signSendLink = async ({ email, lang }: { email: string, lang: string }) => { + await apiClient.authSendLink({ email, lang }) } export const renewSession = async () => { diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 8004b445..9acb96dd 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -93,12 +93,11 @@ export const apiClient = { authCheckEmail: async ({ email }) => { // check if email is used const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise() - console.debug('[api-client] authCheckEmail', response) return response.data.isEmailUsed }, - authSendLink: async ({ email }) => { + authSendLink: async ({ email, lang }) => { // send link with code on email - const response = await publicGraphQLClient.query(authSendLinkMutation, { email }).toPromise() + const response = await publicGraphQLClient.mutation(authSendLinkMutation, { email, lang }).toPromise() return response.data.reset }, confirmEmail: async ({ token }: { token: string }) => {