Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Confirmation Pop-up to Prevent Accidental Exception Deletions #10283

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"archived_files": "Archived Files",
"are_non_editable_fields": "are non-editable fields",
"are_you_still_watching": "Are you still watching?",
"are_you_sure": "Are you sure?",
"are_you_sure_want_to_delete": "Are you sure you want to delete {{name}}?",
"are_you_sure_want_to_delete_this_record": "Are you sure want to delete this record?",
"are_you_sure_want_to_remove": "Are you sure you want to remove {{name}} from the patient? This action cannot be undone",
Expand Down Expand Up @@ -1982,6 +1983,8 @@
"thank_you_for_choosing": "Thank you for choosing our care service",
"the_request_for_resources_placed_by_yourself_is": "The request for resource (details below) placed by yourself is",
"third_party_software_licenses": "Third Party Software Licenses",
"this_will_permanently_remove_the_exception": "This action will permanently remove the exception",
"this_will_permanently_remove_the_template": "This action will permanently remove the template",
"time": "Time",
"time_slot": "Time Slot",
"title_of_request": "Title of Request",
Expand Down
49 changes: 40 additions & 9 deletions src/pages/Scheduling/ScheduleExceptions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { format, parseISO } from "date-fns";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";

Expand All @@ -9,6 +10,14 @@ import ColoredIndicator from "@/CAREUI/display/ColoredIndicator";
import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";
import {
modamaan marked this conversation as resolved.
Show resolved Hide resolved
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";

import Loading from "@/components/Common/Loading";

Expand Down Expand Up @@ -63,6 +72,7 @@ const ScheduleExceptionItem = (
) => {
const { t } = useTranslation();
const queryClient = useQueryClient();
const [open, setOpen] = useState(false);

const { mutate: deleteException, isPending } = useMutation({
mutationFn: mutate(scheduleApis.exceptions.delete, {
Expand Down Expand Up @@ -112,15 +122,36 @@ const ScheduleExceptionItem = (
</span>
</div>
</div>
<Button
variant="secondary"
size="sm"
disabled={isPending}
onClick={() => deleteException(undefined)}
>
<CareIcon icon="l-minus-circle" className="text-base" />
<span className="ml-2">{t("remove")}</span>
</Button>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="secondary" size="sm" disabled={isPending}>
<CareIcon icon="l-minus-circle" className="text-base" />
<span className="ml-2">{t("remove")}</span>
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>{t("are_you_sure")}</DialogTitle>
<DialogDescription>
{t("this_will_permanently_remove_the_exception")}
</DialogDescription>
</DialogHeader>
<div className="flex justify-end space-x-2">
<Button variant="outline" onClick={() => setOpen(false)}>
{t("cancel")}
</Button>
<Button
variant="destructive"
onClick={() => {
deleteException(undefined);
modamaan marked this conversation as resolved.
Show resolved Hide resolved
setOpen(false);
}}
>
{t("remove")}
</Button>
</div>
</DialogContent>
</Dialog>
</div>
{/* TODO: Add this information */}
{/* <div className="px-4 py-2">
Expand Down
77 changes: 62 additions & 15 deletions src/pages/Scheduling/components/CreateScheduleTemplateSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { isAfter, isBefore, parse } from "date-fns";
import { ArrowRightIcon } from "lucide-react";
import { useQueryParams } from "raviger";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Trans } from "react-i18next";
Expand All @@ -17,6 +18,14 @@ import WeekdayCheckbox, {

import { Button } from "@/components/ui/button";
import { DatePicker } from "@/components/ui/date-picker";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Form,
FormControl,
Expand Down Expand Up @@ -235,6 +244,9 @@ export default function CreateScheduleTemplateSheet({
);
};

const [openDialog, setOpenDialog] = useState(false);
const [removeIndex, setRemoveIndex] = useState<number | null>(null);

return (
<Sheet
open={qParams.sheet === "create_template"}
Expand Down Expand Up @@ -351,21 +363,56 @@ export default function CreateScheduleTemplateSheet({
{form.watch(`availabilities.${index}.name`)}
</span>
</div>
<Button
type="button"
variant="secondary"
size="sm"
className="text-gray-600 hover:text-gray-900"
onClick={() => {
const availabilities =
form.getValues("availabilities");
availabilities.splice(index, 1);
form.setValue("availabilities", availabilities);
}}
>
<CareIcon icon="l-trash" className="text-base" />
<span className="ml-2">{t("remove")}</span>
</Button>
<Dialog open={openDialog} onOpenChange={setOpenDialog}>
<DialogTrigger asChild>
<Button
type="button"
variant="secondary"
size="sm"
className="text-gray-600 hover:text-gray-900"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not modify the colors, also use danger variant for destructive actions

Suggested change
className="text-gray-600 hover:text-gray-900"

onClick={() => {
setRemoveIndex(index);
setOpenDialog(true);
}}
>
<CareIcon icon="l-trash" className="text-base" />
<span className="ml-2">{t("remove")}</span>
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>{t("are_you_sure")}</DialogTitle>
<DialogDescription>
{t("this_will_permanently_remove_the_template")}
</DialogDescription>
</DialogHeader>
<div className="flex justify-end space-x-2">
<Button
variant="outline"
onClick={() => setOpenDialog(false)}
>
{t("cancel")}
</Button>
<Button
variant="destructive"
onClick={() => {
const availabilities =
form.getValues("availabilities");
if (removeIndex !== null) {
availabilities.splice(removeIndex, 1);
form.setValue(
"availabilities",
availabilities,
);
}
setOpenDialog(false);
}}
>
{t("remove")}
</Button>
</div>
</DialogContent>
</Dialog>
</div>

<div className="grid grid-cols-2 gap-x-6 gap-y-4">
Expand Down
57 changes: 47 additions & 10 deletions src/pages/Scheduling/components/EditScheduleTemplateSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import WeekdayCheckbox, {

import { Button } from "@/components/ui/button";
import { DatePicker } from "@/components/ui/date-picker";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Form,
FormControl,
Expand Down Expand Up @@ -126,6 +134,7 @@ const ScheduleTemplateEditor = ({
}) => {
const { t } = useTranslation();
const queryClient = useQueryClient();
const [isDialogOpen, setDialogOpen] = useState(false);

const templateFormSchema = z
.object({
Expand Down Expand Up @@ -250,16 +259,44 @@ const ScheduleTemplateEditor = ({
</div>

<div className="flex justify-end gap-2">
<Button
type="button"
variant="outline"
onClick={() => deleteTemplate()}
disabled={isProcessing}
size="sm"
>
<Trash2Icon />
{isDeleting ? t("deleting") : t("delete")}
</Button>
<Dialog open={isDialogOpen} onOpenChange={setDialogOpen}>
<DialogTrigger asChild>
<Button
type="button"
variant="outline"
disabled={isProcessing}
size="sm"
>
<Trash2Icon />
{isDeleting ? t("deleting") : t("delete")}
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>{t("are_you_sure")}</DialogTitle>
<DialogDescription>
{t("this_will_permanently_remove_the_template")}
</DialogDescription>
</DialogHeader>
<div className="flex justify-end space-x-2">
<Button
variant="outline"
onClick={() => setDialogOpen(false)}
>
{t("cancel")}
</Button>
<Button
variant="destructive"
onClick={() => {
deleteTemplate();
setDialogOpen(false);
}}
>
{t("delete")}
</Button>
</div>
</DialogContent>
</Dialog>
<Button
variant="primary"
type="submit"
Expand Down
Loading