Files
no-copy-frontend/src/app/ui/settings/personal-data-settings.tsx
T

94 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-12-01 15:21:56 +07:00
'use client'
2025-12-16 20:26:17 +07:00
import { useTranslations } from 'next-intl';
2026-02-03 17:31:27 +07:00
import { useActionState, useState, useEffect } from 'react';
import { getUserData } from '@/app/actions/action';
import { useQuery } from '@tanstack/react-query';
2025-12-01 15:21:56 +07:00
export default function PersonalDataSettings() {
const [errorMessage, formAction, isPending] = useActionState(
(state: void | undefined, formData: FormData) => {
console.log(formData);
},
undefined
);
2026-02-03 17:31:27 +07:00
const {
data: userData,
isLoading,
isError,
error
} = useQuery({
queryKey: ['userData'],
queryFn: () => {
return getUserData();
}
});
2025-12-16 20:26:17 +07:00
const t = useTranslations('Global');
2025-12-01 15:21:56 +07:00
return (
<div className="settings-form">
<div className="form-section">
2025-12-16 20:26:17 +07:00
<h3 className="form-section-title">
{t('personal-data')}
</h3>
2025-12-01 15:21:56 +07:00
<form action={formAction}>
<div className="form-group">
2025-12-16 20:26:17 +07:00
<label className="form-label">
{t('full-name')}:
</label>
2026-02-03 17:31:27 +07:00
<input
type="text"
name="full_name"
className="form-input"
2026-02-05 11:55:02 +07:00
defaultValue={userData?.fullName}
2026-02-03 17:31:27 +07:00
/>
2025-12-01 15:21:56 +07:00
</div>
2026-02-05 11:55:02 +07:00
{userData?.company && (
2026-02-03 17:31:27 +07:00
<div className="form-group">
<label className="form-label">
{t('company')}:
</label>
<input
type="text"
name="company"
className="form-input"
2026-02-05 11:55:02 +07:00
defaultValue={userData?.company}
2026-02-03 17:31:27 +07:00
/>
</div>
)}
2025-12-01 15:21:56 +07:00
<div className="form-group">
2025-12-16 20:26:17 +07:00
<label className="form-label">
{t('email')}:
</label>
2026-02-03 17:31:27 +07:00
<input
type="text"
name="email"
className="form-input"
2026-02-05 11:55:02 +07:00
defaultValue={userData?.email}
2026-02-03 17:31:27 +07:00
disabled={true}
/>
2025-12-01 15:21:56 +07:00
<small>
2025-12-16 20:26:17 +07:00
{t('email-cant-change')}
2025-12-01 15:21:56 +07:00
</small>
</div>
<div className="form-group">
2025-12-16 20:26:17 +07:00
<label className="form-label">
{t('phone')}:
</label>
2026-02-03 17:31:27 +07:00
<input
type="phone"
name="phone"
className="form-input"
2026-02-05 11:55:02 +07:00
defaultValue={userData?.phone}
2026-02-03 17:31:27 +07:00
/>
2025-12-01 15:21:56 +07:00
</div>
2025-12-16 20:26:17 +07:00
<button type="submit" className="btn btn-primary">
{t('save-changes')}
</button>
2025-12-01 15:21:56 +07:00
</form>
</div >
</div >
)
}