fix
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useForm, Controller, SubmitHandler } from "react-hook-form";
|
||||
import type { User } from "@/types";
|
||||
@@ -10,6 +9,8 @@ import { Input } from "@/components/ui/input";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { BirthdatePicker } from "@/components/ui/birthdate-picker";
|
||||
import { UpdateUser } from "@/actions/auth";
|
||||
import { toast } from "sonner";
|
||||
import { Check, X } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
user: User | null;
|
||||
@@ -24,7 +25,6 @@ interface FormData {
|
||||
|
||||
export default function Profile({ user, setUser }: Props) {
|
||||
const t = useTranslations("MePage.items.profile");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const { register, handleSubmit, control, formState: { errors, isSubmitting } } = useForm<FormData>({
|
||||
defaultValues: {
|
||||
@@ -35,15 +35,16 @@ export default function Profile({ user, setUser }: Props) {
|
||||
});
|
||||
|
||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await UpdateUser(data.first_name, data.second_name, data.birth_date);
|
||||
|
||||
if (response == null) setError(t("form.updateError"))
|
||||
else setUser(response)
|
||||
if (response == null) toast(t("form.updateError"), { icon: <X size={16} /> })
|
||||
else {
|
||||
setUser(response)
|
||||
toast(t("form.successfullyUpdated"), { icon: <Check size={16} /> })
|
||||
}
|
||||
} catch {
|
||||
setError(t("form.updateError"))
|
||||
toast(t("form.updateError"), { icon: <X size={16} /> })
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,7 +107,6 @@ export default function Profile({ user, setUser }: Props) {
|
||||
{isSubmitting && <Spinner />}
|
||||
{t("form.save")}
|
||||
</Button>
|
||||
{error && <FieldError className="text-center">{error}</FieldError>}
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user