diff --git a/src/components/AddressMap.tsx b/src/components/AddressMap.tsx
index a9c2f3c..c29696e 100644
--- a/src/components/AddressMap.tsx
+++ b/src/components/AddressMap.tsx
@@ -30,7 +30,7 @@ const THROTTLE_MS = 2000;
const DEBOUNCE_MS = 400;
export default function AddressMap({ onNewAddressDescriptor, initialAddressDescriptor, titulo }: AddressMapProps) {
- const isEdit = useRef(Boolean(initialAddressDescriptor));
+ const isEdit = useRef(initialAddressDescriptor?.address !== '');
const [status, setStatus] = useState
('unknown');
const [lngLat, setLngLat] = useState(initialAddressDescriptor?.coordinates ?? undefined);
const [addressDescriptor, setAddressDescriptor] = useState({
diff --git a/src/components/HelpOffers/CreateHelpOffer.tsx b/src/components/HelpOffers/CreateHelpOffer.tsx
index 19f1d90..637bed3 100644
--- a/src/components/HelpOffers/CreateHelpOffer.tsx
+++ b/src/components/HelpOffers/CreateHelpOffer.tsx
@@ -7,8 +7,10 @@ import { toast } from 'sonner';
import { useRouter } from 'next/navigation';
import { HelpRequestInsert } from '@/types/Requests';
import { useSession } from '@/context/SessionProvider';
+import { User } from '@supabase/auth-js';
+import { HeartHandshake } from 'lucide-react';
-function formToDatabaseMap(userId: string | null, formData: HelpOfferFormData): HelpRequestInsert {
+function formToDatabaseMap(user: User, formData: HelpOfferFormData): HelpRequestInsert {
return {
description: formData.comentarios,
resources: {
@@ -17,7 +19,7 @@ function formToDatabaseMap(userId: string | null, formData: HelpOfferFormData):
availability: formData.disponibilidad,
},
town_id: formData.pueblo,
- user_id: userId,
+ user_id: user.id,
type: 'ofrece',
other_help: formData.otraAyuda,
help_type: formData.tiposAyuda,
@@ -26,7 +28,7 @@ function formToDatabaseMap(userId: string | null, formData: HelpOfferFormData):
name: formData.nombre,
contact_info: formData.telefono,
additional_info: {
- email: formData.email,
+ email: user.email || user.user_metadata?.email,
experience: formData.experiencia,
},
};
@@ -35,11 +37,13 @@ function formToDatabaseMap(userId: string | null, formData: HelpOfferFormData):
export default function CreateHelpOffer() {
const queryClient = useQueryClient();
const router = useRouter();
- const session = useSession();
+ const { user } = useSession();
const mutation = useMutation({
- mutationFn: (data: HelpOfferFormData) =>
- helpRequestService.createRequest(formToDatabaseMap(session.user?.id ?? null, data)),
+ mutationFn: (data: HelpOfferFormData) => {
+ if (!user) throw 'Sesión no iniciada';
+ return helpRequestService.createRequest(formToDatabaseMap(user, data));
+ },
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['help_requests'] });
router.push('/casos-activos/ofertas');
@@ -50,5 +54,22 @@ export default function CreateHelpOffer() {
},
});
- return ;
+ return (
+
+
Ofrecer ayuda
+
+
+
+
+
Me apunto como voluntario
+
+ Al registrarte como voluntario, te comprometes a seguir las indicaciones de las autoridades y los
+ protocolos establecidos.
+
+
+
+
+
+
+ );
}
diff --git a/src/components/HelpOffers/EditHelpOffer.tsx b/src/components/HelpOffers/EditHelpOffer.tsx
index 99da9a7..bf0dc4f 100644
--- a/src/components/HelpOffers/EditHelpOffer.tsx
+++ b/src/components/HelpOffers/EditHelpOffer.tsx
@@ -31,7 +31,7 @@ function formToDatabaseMap(request: HelpRequestData, formData: HelpOfferFormData
name: formData.nombre,
contact_info: formData.telefono,
additional_info: {
- email: formData.email,
+ email: request.additional_info.email,
experience: formData.experiencia,
},
};
@@ -54,10 +54,7 @@ export default function EditHelpOffer({ request }: EditHelpOfferProps) {
});
return (
diff --git a/src/components/HelpOffers/HelpOfferForm.tsx b/src/components/HelpOffers/HelpOfferForm.tsx
index 0465e02..21f1e56 100644
--- a/src/components/HelpOffers/HelpOfferForm.tsx
+++ b/src/components/HelpOffers/HelpOfferForm.tsx
@@ -6,12 +6,12 @@ import { HelpRequestData, HelpRequestHelpType } from '@/types/Requests';
import { useSession } from '@/context/SessionProvider';
import { tiposAyudaArray } from '@/helpers/constants';
import { Town } from '@/types/Town';
+import Unauthorized from '@/components/Unauthorized';
export type HelpOfferFormData = {
aceptaProtocolo: boolean;
nombre: string;
telefono: string;
- email: string;
ubicacion: string;
tiposAyuda: HelpRequestHelpType[];
otraAyuda: string;
@@ -32,12 +32,11 @@ export interface HelpOfferProps {
}
export default function HelpOfferForm({ town, data, buttonText, submitMutation }: HelpOfferProps) {
- const session = useSession();
+ const { user } = useSession();
const [formData, setFormData] = useState({
- nombre: data?.name || session?.user?.user_metadata?.full_name || '',
- telefono: data?.contact_info || session?.user?.user_metadata?.telefono || '',
- email: data?.additional_info?.email || session?.user?.user_metadata?.email || '',
+ nombre: data?.name || user?.user_metadata?.full_name || user?.user_metadata?.nombre || '',
+ telefono: data?.contact_info || user?.user_metadata?.telefono || '',
ubicacion: data?.location || '',
tiposAyuda: data?.help_type || [],
otraAyuda: data?.other_help || '',
@@ -81,6 +80,8 @@ export default function HelpOfferForm({ town, data, buttonText, submitMutation }
await submitMutation(formData);
};
+ if (!user) return ;
+
return (
);
}