Skip to content

Commit

Permalink
feat(SolicitudCard): add PhoneInfo component to abstract assigment lo…
Browse files Browse the repository at this point in the history
…gic from SolicitudCard
  • Loading branch information
PauSansa committed Nov 6, 2024
1 parent 1525d44 commit 50a0043
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
27 changes: 27 additions & 0 deletions src/components/PhoneInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useQuery } from '@tanstack/react-query';
import { helpRequestService } from '@/lib/service';
import { useSession } from '@/context/SessionProvider';

export default function PhoneInfo({ caseInfo }) {
const session = useSession();

const {
data: assignments,
isLoading,
error,
} = useQuery({
queryKey: ['help_request_assignments', { id: caseInfo.id }],
queryFn: () => helpRequestService.getAssignments(caseInfo.id),
});

if (error || isLoading) return <></>;

const userAssignment = assignments?.find((x) => x.user_id === session.user?.id);

return (
<span className="break-words">
<span className="font-semibold">Contacto:</span>{' '}
{!!userAssignment ? caseInfo.contact_info : 'Ayuda a esta persona para ver sus datos de contacto'}
</span>
);
}
21 changes: 2 additions & 19 deletions src/components/SolicitudCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { AlertTriangle, Calendar, MapPin, MapPinned, Megaphone, Phone, Users } f
import { tiposAyudaOptions } from '@/helpers/constants';
import Link from 'next/link';
import { useSession } from '@/context/SessionProvider';
import { helpRequestService } from '@/lib/service';
import { useQuery } from '@tanstack/react-query';
import { HelpRequestAdditionalInfo, HelpRequestData, HelpRequestAssignmentData } from '@/types/Requests';
import { Town } from '@/types/Town';
import AsignarSolicitudButton from '@/components/AsignarSolicitudButton';
import SolicitudHelpCount from '@/components/SolicitudHelpCount';
import PhoneInfo from '@/components/PhoneInfo.js';

type SolicitudCardProps = {
caso: HelpRequestData;
Expand All @@ -33,19 +32,6 @@ export default function SolicitudCard({

const additionalInfo = caso.additional_info as HelpRequestAdditionalInfo;

const {
data: assignments,
isLoading,
error,
} = useQuery<HelpRequestAssignmentData[]>({
queryKey: ['help_request_assignments', { id: caso.id }],
queryFn: () => helpRequestService.getAssignments(caso.id),
});

if (error || isLoading) return <></>;

const userAssignment = assignments?.find((x) => x.user_id === session.user?.id);

const special_situations = 'special_situations' in additionalInfo ? additionalInfo.special_situations : undefined;
const email = 'email' in additionalInfo ? additionalInfo.email : undefined;
return (
Expand Down Expand Up @@ -118,10 +104,7 @@ export default function SolicitudCard({
{caso.contact_info && (
<div className="flex items-start gap-2">
<Phone className="h-4 w-4 text-gray-500 flex-shrink-0 mt-1" />
<span className="break-words">
<span className="font-semibold">Contacto:</span>{' '}
{!!userAssignment ? caso.contact_info : 'Ayuda a esta persona para ver sus datos de contacto'}
</span>
<PhoneInfo caseInfo={caso} />
</div>
)}
{caso.urgency && (
Expand Down

0 comments on commit 50a0043

Please sign in to comment.