changed
This commit is contained in:
35
src/widgets/cabinet/lib/hooks/useProfile.ts
Normal file
35
src/widgets/cabinet/lib/hooks/useProfile.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import type { UserProfile } from '../types';
|
||||
|
||||
interface ProfileForm extends UserProfile {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
|
||||
export const useProfile = (initial: UserProfile) => {
|
||||
const [form, setForm] = useState<ProfileForm>({
|
||||
...initial,
|
||||
currentPassword: '',
|
||||
newPassword: '',
|
||||
confirmPassword: '',
|
||||
});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [saved, setSaved] = useState(false);
|
||||
|
||||
const handleChange = (field: keyof ProfileForm, value: string) => {
|
||||
setForm((prev) => ({ ...prev, [field]: value }));
|
||||
setSaved(false);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
// TODO: replace with real API call
|
||||
await new Promise((res) => setTimeout(res, 800));
|
||||
setIsSaving(false);
|
||||
setSaved(true);
|
||||
};
|
||||
|
||||
return { form, isSaving, saved, handleChange, handleSave };
|
||||
};
|
||||
Reference in New Issue
Block a user