Skip to content

Commit

Permalink
Add error message to frontend modal
Browse files Browse the repository at this point in the history
  • Loading branch information
canjalal committed Oct 22, 2024
1 parent c4664a5 commit f491f68
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const iep = router({
const existingTasks = await req.ctx.db
.selectFrom("task")
.where("subgoal_id", "=", subgoal_id)
.where("assignee_id", "=", para_ids)
.where("assignee_id", "in", para_ids)
.selectAll()
.execute();

Expand Down
42 changes: 29 additions & 13 deletions src/components/benchmarks/BenchmarkAssignmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ export const BenchmarkAssignmentModal = (
subgoal_id: props.benchmark_id,
});

const [errorMessage, setErrorMessage] = useState<string>("");

const assignTaskToPara = trpc.iep.assignTaskToParas.useMutation();

const handleParaToggle = (paraId: string) => () => {
setErrorMessage("");
setSelectedParaIds((prev) => {
if (prev.includes(paraId)) {
return prev.filter((id) => id !== paraId);
Expand All @@ -69,6 +72,7 @@ export const BenchmarkAssignmentModal = (
const handleClose = () => {
props.onClose();
setSelectedParaIds([]);
setErrorMessage("");
setCurrentModalSelection("PARA_SELECTION");
};

Expand All @@ -90,19 +94,25 @@ export const BenchmarkAssignmentModal = (
setCurrentModalSelection(nextStep);
} else {
// Reached end, save
await assignTaskToPara.mutateAsync({
subgoal_id: props.benchmark_id,
para_ids: selectedParaIds,
due_date:
assignmentDuration.type === "until_date"
? assignmentDuration.date
: undefined,
trial_count:
assignmentDuration.type === "minimum_number_of_collections"
? assignmentDuration.minimumNumberOfCollections
: undefined,
});
handleClose();
try {
await assignTaskToPara.mutateAsync({
subgoal_id: props.benchmark_id,
para_ids: selectedParaIds,
due_date:
assignmentDuration.type === "until_date"
? assignmentDuration.date
: undefined,
trial_count:
assignmentDuration.type === "minimum_number_of_collections"
? assignmentDuration.minimumNumberOfCollections
: undefined,
});
handleClose();
} catch (err) {
// TODO: issue #450
console.log(err);
setErrorMessage(err.message as string);

Check failure on line 114 in src/components/benchmarks/BenchmarkAssignmentModal.tsx

View workflow job for this annotation

GitHub Actions / type-check

'err' is of type 'unknown'.
}
}
};

Expand Down Expand Up @@ -173,6 +183,12 @@ export const BenchmarkAssignmentModal = (
/>
</Box>
)}

{errorMessage && (
<Box className={$benchmark.benchmarkDescriptionBox}>
{errorMessage}
</Box>
)}
<DialogActions>
{currentModalSelection !== STEPS[0] && (
<Button
Expand Down

0 comments on commit f491f68

Please sign in to comment.