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

feat: Use MUI dialog for restart session #2777

Merged
merged 1 commit into from
Feb 13, 2024
Merged
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
33 changes: 22 additions & 11 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Reset from "ui/icons/Reset";
import { useStore } from "../pages/FlowEditor/lib/store";
import { rootFlowPath, rootTeamPath } from "../routes/utils";
import AnalyticsDisabledBanner from "./AnalyticsDisabledBanner";
import { ConfirmationDialog } from "./ConfirmationDialog";
import FeatureFlagBanner from "./FeatureFlagBanner";
import TestEnvironmentBanner from "./TestEnvironmentBanner";

Expand Down Expand Up @@ -323,12 +324,12 @@ const PublicToolbar: React.FC<{

const { trackFlowDirectionChange } = useAnalyticsTracking();

const handleRestart = async () => {
if (
confirm(
"Are you sure you want to restart? This will delete your previous answers",
)
) {
const [isDialogOpen, setIsDialogOpen] = useState(false);
const openConfirmationDialog = () => setIsDialogOpen(true);

const handleRestart = (isConfirmed: boolean) => {
setIsDialogOpen(false);
if (isConfirmed) {
trackFlowDirectionChange("reset");
if (path === ApplicationPath.SingleSession) {
clearLocalFlow(id);
Expand Down Expand Up @@ -358,7 +359,7 @@ const PublicToolbar: React.FC<{
{showResetButton && (
<IconButton
color="secondary"
onClick={handleRestart}
onClick={openConfirmationDialog}
aria-label="Restart Application"
size="large"
>
Expand All @@ -378,6 +379,18 @@ const PublicToolbar: React.FC<{
<AnalyticsDisabledBanner />
<TestEnvironmentBanner />
<FeatureFlagBanner />
<ConfirmationDialog
open={isDialogOpen}
onClose={handleRestart}
title="Confirm"
confirmText="Yes"
cancelText="No"
>
<Typography>
Are you sure you want to restart? This will delete your previous
answers
</Typography>
</ConfirmationDialog>
</>
);
};
Expand Down Expand Up @@ -415,14 +428,12 @@ const EditorToolbar: React.FC<{
setOpen(!open);
};

const isFlowSettingsVisible =
route.data.flow && canUserEditTeam(team.slug);
const isFlowSettingsVisible = route.data.flow && canUserEditTeam(team.slug);

const isTeamSettingsVisible =
route.data.team && !route.data.flow && canUserEditTeam(team.slug);

const isGlobalSettingsVisible =
!route.data.team && user?.isPlatformAdmin;
const isGlobalSettingsVisible = !route.data.team && user?.isPlatformAdmin;

return (
<>
Expand Down
Loading