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 Loading State to Action Delete & Person Delete Buttons #694

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function ActionSettingsTab({ environmentId, actionClass, setOpen
},
});
const [isUpdatingAction, setIsUpdatingAction] = useState(false);
const [isDeletingAction, setIsDeletingAction] = useState(false);

const onSubmit = async (data) => {
const filteredNoCodeConfig = filterNoCodeConfig(data.noCodeConfig as NoCodeConfig);
Expand Down Expand Up @@ -81,6 +82,20 @@ export default function ActionSettingsTab({ environmentId, actionClass, setOpen
if (match === "no") toast.error("Your survey would not be shown.");
};

const handleDeleteAction = async () => {
try {
setIsDeletingAction(true);
await deleteActionClass(environmentId, actionClass.id);
router.refresh();
toast.success("Action deleted successfully");
setOpen(false);
} catch (error) {
toast.error("Something went wrong. Please try again.");
} finally {
setIsDeletingAction(false);
}
};

return (
<div>
<form className="space-y-4" onSubmit={handleSubmit(onSubmit)}>
Expand Down Expand Up @@ -288,18 +303,10 @@ export default function ActionSettingsTab({ environmentId, actionClass, setOpen
<DeleteDialog
open={openDeleteDialog}
setOpen={setOpenDeleteDialog}
isDeleting={isDeletingAction}
deleteWhat={"Action"}
text="Are you sure you want to delete this action? This also removes this action as a trigger from all your surveys."
onDelete={async () => {
setOpen(false);
try {
await deleteActionClass(environmentId, actionClass.id);
router.refresh();
toast.success("Action deleted successfully");
} catch (error) {
toast.error("Something went wrong. Please try again.");
}
}}
onDelete={handleDeleteAction}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ export default function HeadingSection({
const router = useRouter();

const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [isDeletingPerson, setIsDeletingPerson] = useState(false);

const handleDeletePerson = async () => {
await deletePersonAction(person.id);
router.push(`/environments/${environmentId}/people`);
toast.success("Person deleted successfully.");
try {
setIsDeletingPerson(true);
await deletePersonAction(person.id);
router.push(`/environments/${environmentId}/people`);
toast.success("Person deleted successfully.");
} catch (error) {
toast.error(error.message);
} finally {
setIsDeletingPerson(false);
}
};

return (
Expand All @@ -46,6 +55,7 @@ export default function HeadingSection({
setOpen={setDeleteDialogOpen}
deleteWhat="person"
onDelete={handleDeletePerson}
isDeleting={isDeletingPerson}
/>
</>
);
Expand Down
Loading