Skip to content

Commit

Permalink
fix: update form data on user change (from null to a value)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinx0 committed Nov 9, 2024
1 parent bb3ff15 commit d8eb7b7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/HelpRequests/HelpRequestForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { ChangeEvent, FormEvent, useCallback, useState } from 'react';
import { ChangeEvent, FormEvent, useCallback, useEffect, useState } from 'react';
import { isValidPhone } from '@/helpers/utils';
import { tiposAyudaArray } from '@/helpers/constants';
import { PhoneInput } from '@/components/input/PhoneInput';
Expand Down Expand Up @@ -59,6 +59,24 @@ export default function HelpRequestForm({
town_id: request?.town_id || 0,
});

useEffect(() => {
setFormData({
nombre: request?.name || user?.user_metadata?.full_name || user?.user_metadata?.nombre || '',
telefono: request?.contact_info || user?.user_metadata?.telefono || '',
ubicacion: request?.location || '',
coordinates: { lat: 0, lng: 0 },
tiposAyuda: request?.help_type || [],
numeroPersonas: request?.number_of_people || 1,
descripcion: request?.description || '',
urgencia: request?.urgency === 'alta' ? 'alta' : request?.urgency === 'media' ? 'media' : 'baja',
situacionEspecial: request?.additional_info?.special_situations || '',
consentimiento: request?.additional_info?.consent || false,
pueblo: '',
status: request?.status || 'active',
town_id: request?.town_id || 0,
});
}, [user, request]);

const handleTipoAyudaChange = (tipo: HelpRequestHelpType) => {
setFormData((prev) => ({
...prev,
Expand Down

0 comments on commit d8eb7b7

Please sign in to comment.