Skip to content

Commit

Permalink
Merge pull request #108 from PauSansa/feat/hide-contact-when-unassigned
Browse files Browse the repository at this point in the history
feat(help-req) - hide contact info if user is not assigned to help request
  • Loading branch information
vsornosa1 authored Nov 6, 2024
2 parents 706f3f3 + 50a0043 commit 941cbd0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 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>
);
}
7 changes: 3 additions & 4 deletions src/components/SolicitudCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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 { HelpRequestAdditionalInfo, HelpRequestData } from '@/types/Requests';
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 Down Expand Up @@ -103,9 +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> {caso.contact_info}
</span>
<PhoneInfo caseInfo={caso} />
</div>
)}
{caso.urgency && (
Expand Down

0 comments on commit 941cbd0

Please sign in to comment.