()
| 5 | import { useToast } from "../hooks/use-toast"; |
| 6 | |
| 7 | export default function CompleteProfile() { |
| 8 | const [searchParams] = useSearchParams(); |
| 9 | const emailParam = searchParams.get('email') || ''; |
| 10 | |
| 11 | const [loading, setLoading] = useState(false); |
| 12 | const [formData, setFormData] = useState({ |
| 13 | email: emailParam, |
| 14 | password: '', // We need password to authenticate the update |
| 15 | legalName: '', |
| 16 | address: { |
| 17 | street: '', |
| 18 | city: '', |
| 19 | state: '', |
| 20 | postalCode: '', |
| 21 | country: '' |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | const { toast } = useToast(); |
| 26 | |
| 27 | const handleChange = (e) => { |
| 28 | const { name, value } = e.target; |
| 29 | if (name.includes('.')) { |
| 30 | const [parent, child] = name.split('.'); |
| 31 | setFormData(prev => ({ |
| 32 | ...prev, |
| 33 | [parent]: { |
| 34 | ...prev[parent], |
| 35 | [child]: value |
| 36 | } |
| 37 | })); |
| 38 | } else { |
| 39 | setFormData(prev => ({ |
| 40 | ...prev, |
| 41 | [name]: value |
| 42 | })); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | const handleSubmit = async (e) => { |
| 47 | e.preventDefault(); |
| 48 | setLoading(true); |
| 49 | |
| 50 | try { |
| 51 | // Validation |
| 52 | if (!formData.legalName || !formData.address.street || !formData.address.city || |
| 53 | !formData.address.state || !formData.address.postalCode || !formData.address.country) { |
| 54 | throw new Error("Please fill in all profile fields"); |
| 55 | } |
| 56 | // Password validation: Not required if user is already authenticated via session |
| 57 | // The backend will handle session-based authentication |
| 58 | // if (!formData.password) { |
| 59 | // throw new Error("Please enter your password to confirm changes"); |
| 60 | // } |
| 61 | |
| 62 | const res = await subdomainAPI.post('/auth/email/complete-profile', formData); |
| 63 | |
| 64 | if (res.message) { |
nothing calls this directly
no test coverage detected