Skip to content

Commit

Permalink
feat: make comments visible to the creator of the request
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinx0 committed Nov 11, 2024
1 parent 9f0754c commit 7a38e80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/solicitudes/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function CasoDetalle() {
</button>
</div>
<SolicitudCard caso={request} showLink={false} showEdit={true} />
<SolicitudComments request_id={request.id} />
<SolicitudComments request={request} />
</div>
);
}
19 changes: 10 additions & 9 deletions src/components/Comments/SolicitudComments.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HelpRequestAssignmentData, HelpRequestComment } from '@/types/Requests';
import { HelpRequestAssignmentData, HelpRequestComment, HelpRequestData } from '@/types/Requests';
import { useQuery } from '@tanstack/react-query';
import { helpRequestService } from '@/lib/service';
import { useSession } from '@/context/SessionProvider';
Expand All @@ -7,17 +7,17 @@ import CommentForm from '@/components/Comments/CommentForm';
import { useRole } from '@/context/RoleProvider';

type SolicitudCommentsProps = {
request_id: number;
request: HelpRequestData;
};

export default function SolicitudComments({ request_id }: SolicitudCommentsProps) {
export default function SolicitudComments({ request }: SolicitudCommentsProps) {
const {
data: comments,
isLoading,
error,
} = useQuery<HelpRequestComment[]>({
queryKey: ['comments', { request_id: request_id }],
queryFn: () => helpRequestService.getComments(request_id),
queryKey: ['comments', { request_id: request.id }],
queryFn: () => helpRequestService.getComments(request.id),
});

const { user } = useSession();
Expand All @@ -29,8 +29,8 @@ export default function SolicitudComments({ request_id }: SolicitudCommentsProps
isLoading: isLoadingAssignments,
error: errorAssignments,
} = useQuery<HelpRequestAssignmentData[]>({
queryKey: ['help_request_assignments', { id: request_id }],
queryFn: () => helpRequestService.getAssignments(request_id),
queryKey: ['help_request_assignments', { id: request.id }],
queryFn: () => helpRequestService.getAssignments(request.id),
});

if (!user) return null;
Expand All @@ -54,15 +54,16 @@ export default function SolicitudComments({ request_id }: SolicitudCommentsProps

const userAssignment = assignments.find((x) => x.user_id === user?.id);
const userIsAssigned = !!userAssignment;
const userIsOwner = user.id === request.user_id;

if (!userIsAssigned && !isAdmin) return null;
if (!userIsAssigned && !isAdmin && !userIsOwner) return null;

return (
<div className="space-y-4 pl-12 xl:pl-24">
{comments.map((comment) => (
<SolicitudComment comment={comment} key={comment.id} />
))}
<CommentForm helpRequestId={request_id} />
<CommentForm helpRequestId={request.id} />
</div>
);
}

0 comments on commit 7a38e80

Please sign in to comment.