import { BasePage, InfoBox } from "@/components/design-elements"; import { ProfileForm } from "@/pages/profile/ProfileForm"; import { useState, useEffect } from "react"; import type { IUser } from "@/types/user"; import type { ApiResponse } from "@/types/api"; import { useGet, usePatch, useGetOnDemand } from "@/hooks/UseApi"; import { useTranslation } from "react-i18next"; import { useAppDispatch } from "@/hooks/AppHooks"; import { setUser as setUserGlobal } from "@/features/authSlice"; import type { FormValues } from "@/pages/profile/ProfileForm"; const Profile = () => { const { t } = useTranslation(); const [user, setUser] = useState | null>(null); const { response, loading } = useGet>(`/profile`, {}, {}); const { get: getOnDemand } = useGetOnDemand(); const dispatch = useAppDispatch(); useEffect(() => { if (response?.data) setUser(response.data); }, [response]); const { patch, loading: isPatching } = usePatch>(); const onSubmit = async (data: FormValues) => { const res = await patch(`/profile`, data); if (res) { const me = await getOnDemand("/me"); if (me?.data) { setUser(me.data); dispatch(setUserGlobal(me.data as IUser)); } } }; const initialData = { firstName: user?.firstName || "", lastName: user?.lastName || "", }; return ( ); }; export default Profile;