Skip to content

Commit

Permalink
Fix duplicate prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Aug 14, 2024
1 parent 053d311 commit bc5e532
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/client/src/pages/overview/boreholeTable/bottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,33 @@ const BottomBar = ({
const { showPrompt, promptIsOpen } = useContext(PromptContext);
const user: User = useSelector((state: ReduxRootState) => state.core_user);
const [copyPromptOpen, setCopyPromptOpen] = useState(false);
const [currentWorkgroup, setCurrentWorkgroup] = useState<number | null>(null);
const enabledWorkgroups = user.data.workgroups.filter(
w => w.disabled === null && !w.supplier && w.roles.includes("EDIT"),
);

const showCopyPromptForSelectedWorkgroup = useCallback(() => {
setCopyPromptOpen(true);
showPrompt(
t("selectWorkgroupToCreateCopy"),
[
{
label: t("cancel"),
},
{
label: "copy",
icon: <CopyIcon />,
variant: "contained",
action: onCopyBorehole,
},
],
<WorkgroupSelect workgroup={workgroup} enabledWorkgroups={enabledWorkgroups} setWorkgroup={setWorkgroup} />,
"400px",
);
}, [enabledWorkgroups, onCopyBorehole, setWorkgroup, showPrompt, t, workgroup]);
setCurrentWorkgroup(workgroup);
if (workgroup != currentWorkgroup || !copyPromptOpen) {
showPrompt(
t("selectWorkgroupToCreateCopy"),
[
{
label: t("cancel"),
},
{
label: "copy",
icon: <CopyIcon />,
variant: "contained",
action: onCopyBorehole,
},
],
<WorkgroupSelect workgroup={workgroup} enabledWorkgroups={enabledWorkgroups} setWorkgroup={setWorkgroup} />,
"400px",
);
}
}, [copyPromptOpen, currentWorkgroup, enabledWorkgroups, onCopyBorehole, setWorkgroup, showPrompt, t, workgroup]);

//Ensures prompt content with the WorkgroupSelect is updated when a workgroup is selected.
useEffect(() => {
Expand Down

0 comments on commit bc5e532

Please sign in to comment.