import { Button, Group, Text, Modal, PasswordInput } from "@mantine/core"; import * as z from "zod"; import { useState } from "react"; import { useDisclosure } from "@mantine/hooks"; import * as React from "react"; import { useForm, zodResolver } from "@mantine/form"; import { changePassword } from "@/features/auth/services/auth-service.ts"; import { notifications } from "@mantine/notifications"; import { useTranslation } from "react-i18next"; export default function ChangePassword() { const { t } = useTranslation(); const [opened, { open, close }] = useDisclosure(false); return (
{t("Password")} {t("You can change your password here.")}
{t("Your password must be a minimum of 8 characters.")}
); } const formSchema = z.object({ oldPassword: z .string({ required_error: "your current password is required" }) .min(8), newPassword: z.string({ required_error: "New password is required" }).min(8), }); type FormValues = z.infer; interface ChangePasswordFormProps { onClose?: () => void; } function ChangePasswordForm({ onClose }: ChangePasswordFormProps) { const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const form = useForm({ validate: zodResolver(formSchema), initialValues: { oldPassword: "", newPassword: "", }, }); async function handleSubmit(data: FormValues) { setIsLoading(true); try { await changePassword({ oldPassword: data.oldPassword, newPassword: data.newPassword, }); notifications.show({ message: t("Password changed successfully"), }); onClose(); } catch (err) { notifications.show({ message: `Error: ${err.response.data.message}`, color: "red", }); } setIsLoading(false); } return (
); }