diff --git a/src/api/auth/use-update-password.ts b/src/api/auth/use-update-password.ts new file mode 100644 index 000000000..92be4e4bc --- /dev/null +++ b/src/api/auth/use-update-password.ts @@ -0,0 +1,44 @@ +import { createMutation } from 'react-query-kit'; + +import { client } from '../common'; + +type Variables = { + password: string; + passwordConfirmation: string; +}; + +type ResponseData = { + email: string; + provider: string; + uid: string; + id: number; + allow_password_change: boolean; + name: string; + nickname: string; + image: string | null; + created_at: string; + updated_at: string; + birthday: string | null; +}; + +type Response = { + success: boolean; + message: string; + data?: ResponseData; +}; + +const updatePasswordRequest = async (variables: Variables) => { + const { data } = await client({ + url: '/v1/users/password', + method: 'PUT', + data: { ...variables }, + headers: { + 'Content-Type': 'application/json', + }, + }); + return data; +}; + +export const useUpdatePassword = createMutation({ + mutationFn: (variables) => updatePasswordRequest(variables), +}); diff --git a/src/app/(app)/settings.tsx b/src/app/(app)/settings.tsx index 43ea00ac8..43e538b27 100644 --- a/src/app/(app)/settings.tsx +++ b/src/app/(app)/settings.tsx @@ -50,6 +50,14 @@ export default function Settings() { text={'settings.account.email'} value={userData?.email ?? ''} /> + + + diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx index 2ba896026..7f9b90955 100644 --- a/src/app/_layout.tsx +++ b/src/app/_layout.tsx @@ -5,6 +5,7 @@ import { BottomSheetModalProvider } from '@gorhom/bottom-sheet'; import { ThemeProvider } from '@react-navigation/native'; import { SplashScreen, Stack } from 'expo-router'; import React from 'react'; +import { useTranslation } from 'react-i18next'; import { StyleSheet } from 'react-native'; import FlashMessage from 'react-native-flash-message'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; @@ -29,12 +30,19 @@ interceptors(); SplashScreen.preventAutoHideAsync(); export default function RootLayout() { + const { t } = useTranslation(); return ( + data.password === data.passwordConfirmation, { + message: translate('updatePassword.error.passwordsMustMatch'), + path: ['passwordConfirmation'], + }); + +export default function UpdatePassword() { + const { t } = useTranslation(); + const navigate = useNavigation(); + + const { mutateAsync: updatePassword } = useUpdatePassword({ + onSuccess: () => { + showMessage({ + message: t('updatePassword.successMessage'), + type: 'success', + }); + navigate.goBack(); + }, + onError: () => { + showMessage({ + message: t('updatePassword.errorMessage'), + type: 'danger', + }); + }, + }); + + const { handleSubmit, control } = useForm({ + resolver: zodResolver(schema), + }); + const onSubmit = async (data: FormValues) => { + await updatePassword(data); + }; + + return ( + <> + + + + + + {t('updatePassword.title')} + + + {t('updatePassword.description')} + + + + + +