Skip to content

Commit

Permalink
fix(OH2-440): Add cancel action on user/group creation/update
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Nov 28, 2024
1 parent 093718e commit 382c207
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 69 deletions.
26 changes: 20 additions & 6 deletions src/components/accessories/admin/users/editGroup/EditGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useParams } from "react-router";
import { useNavigate } from "react-router-dom";

import checkIcon from "../../../../../assets/check-icon.png";
import warningIcon from "../../../../../assets/warning-icon.png";
import Button from "../../../button/Button";
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
import InfoBox from "../../../infoBox/InfoBox";
Expand Down Expand Up @@ -42,6 +43,8 @@ export const EditGroup = () => {
const { id } = useParams();
const canUpdatePermissions = usePermission("grouppermission.update");

const [openResetConfirmation, setOpenResetConfirmation] = useState(false);

const update = useAppSelector((state) => state.usergroups.update);
const permissions = useAppSelector((state) => state.permissions.getAll);
const group = useAppSelector((state) => state.usergroups.currentGroup);
Expand Down Expand Up @@ -130,9 +133,9 @@ export const EditGroup = () => {
};
}, []);

const handleFormReset = () => {
resetForm();
setGroupPermissions(group.data?.permissions ?? []);
const handleResetConfirmation = () => {
setOpenResetConfirmation(false);
navigate(-1);
};

const handleCheckboxChange = useCallback(
Expand Down Expand Up @@ -262,16 +265,27 @@ export const EditGroup = () => {
</div>
<div className="reset_button">
<Button
dataCy="cancel-form"
type="reset"
variant="text"
disabled={!!update.isLoading || !(dirty || dirtyPermissions)}
onClick={handleFormReset}
disabled={update.isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
{t("common.reset")}
{t("common.cancel")}
</Button>
</div>
</div>
</form>
<ConfirmationDialog
isOpen={openResetConfirmation}
title={t("common.cancel")}
info={t("common.resetform")}
icon={warningIcon}
primaryButtonLabel={t("common.ok")}
secondaryButtonLabel={t("common.discard")}
handlePrimaryButtonClick={handleResetConfirmation}
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
/>
<ConfirmationDialog
isOpen={update.hasSucceeded}
title={t("user.groupUpdated")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
margin-top: 25px;
padding: 0px 15px;
flex-direction: row-reverse;
gap: 2px;
@include susy-media($smartphone_small) {
display: block;
}
Expand Down
30 changes: 23 additions & 7 deletions src/components/accessories/admin/users/editUser/EditUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
TextField as MuiTextField,
} from "@mui/material";
import { useFormik } from "formik";
import React, { ReactNode, useCallback } from "react";
import React, { ReactNode, useCallback, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";

import { UserDTO, UserGroupDTO } from "../../../../../generated";

import checkIcon from "../../../../../assets/check-icon.png";
import warningIcon from "../../../../../assets/warning-icon.png";
import Button from "../../../button/Button";
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
import InfoBox from "../../../infoBox/InfoBox";
Expand Down Expand Up @@ -44,6 +45,8 @@ export const EditUserForm = ({
const { t } = useTranslation();
const navigate = useNavigate();

const [openResetConfirmation, setOpenResetConfirmation] = useState(false);

const handleFormSubmit = (values: UserDTO & { passwd2: string }) => {
const { passwd2, ...userDTO } = values;
if (userDTO.passwd === undefined) {
Expand All @@ -59,7 +62,6 @@ export const EditUserForm = ({
getFieldProps,
isValid,
dirty,
resetForm,
errors,
touched,
values,
Expand All @@ -71,6 +73,11 @@ export const EditUserForm = ({
onSubmit: handleFormSubmit,
});

const handleResetConfirmation = () => {
setOpenResetConfirmation(false);
navigate(-1);
};

const handleCheckboxChange = useCallback(
(fieldName: string) => (value: boolean) => {
setFieldValue(fieldName, value);
Expand Down Expand Up @@ -192,18 +199,27 @@ export const EditUserForm = ({
</div>
<div className="reset_button">
<Button
dataCy="cancel-form"
type="reset"
variant="text"
disabled={!!isLoading || !dirty}
onClick={async () => {
resetForm();
}}
disabled={isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
{t("common.reset")}
{t("common.cancel")}
</Button>
</div>
</div>
</form>
<ConfirmationDialog
isOpen={openResetConfirmation}
title={t("common.cancel")}
info={t("common.resetform")}
icon={warningIcon}
primaryButtonLabel={t("common.ok")}
secondaryButtonLabel={t("common.discard")}
handlePrimaryButtonClick={handleResetConfirmation}
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
/>
<ConfirmationDialog
isOpen={hasSucceeded}
title={t("user.updatedSuccessTitle")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
display: flex;
margin-top: 25px;
padding: 0px 15px;
gap: 2px;
flex-direction: row-reverse;
@include susy-media($smartphone_small) {
display: block;
Expand Down
30 changes: 23 additions & 7 deletions src/components/accessories/admin/users/newGroup/NewGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useFormik } from "formik";
import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
import React, { useCallback, useEffect } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";

import checkIcon from "../../../../../assets/check-icon.png";
import warningIcon from "../../../../../assets/warning-icon.png";
import Button from "../../../button/Button";
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
import InfoBox from "../../../infoBox/InfoBox";
Expand Down Expand Up @@ -32,6 +33,8 @@ export const NewGroup = () => {
const { t } = useTranslation();
const navigate = useNavigate();

const [openResetConfirmation, setOpenResetConfirmation] = useState(false);

const create = useAppSelector((state) => state.usergroups.create);

const {
Expand All @@ -40,7 +43,6 @@ export const NewGroup = () => {
getFieldProps,
isValid,
dirty,
resetForm,
errors,
touched,
values,
Expand All @@ -59,6 +61,11 @@ export const NewGroup = () => {
};
}, [dispatch]);

const handleResetConfirmation = () => {
setOpenResetConfirmation(false);
navigate(-1);
};

const handleCheckboxChange = useCallback(
(fieldName: string) => (value: boolean) => {
setFieldValue(fieldName, value);
Expand Down Expand Up @@ -123,18 +130,27 @@ export const NewGroup = () => {
</div>
<div className="reset_button">
<Button
dataCy="cancel-form"
type="reset"
variant="text"
disabled={!!create.isLoading || !dirty}
onClick={async () => {
resetForm();
}}
disabled={create.isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
{t("common.reset")}
{t("common.cancel")}
</Button>
</div>
</div>
</form>
<ConfirmationDialog
isOpen={openResetConfirmation}
title={t("common.cancel")}
info={t("common.resetform")}
icon={warningIcon}
primaryButtonLabel={t("common.ok")}
secondaryButtonLabel={t("common.discard")}
handlePrimaryButtonClick={handleResetConfirmation}
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
/>
<ConfirmationDialog
isOpen={create.hasSucceeded}
title={t("user.groupCreated")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
display: flex;
margin-top: 25px;
padding: 0px 15px;
gap: 2px;
flex-direction: row-reverse;
@include susy-media($smartphone_small) {
display: block;
Expand Down
26 changes: 21 additions & 5 deletions src/components/accessories/admin/users/newUser/NewUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@mui/material";
import { useFormik } from "formik";
import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
import React, { ReactNode, useCallback, useEffect } from "react";
import React, { ReactNode, useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import checkIcon from "../../../../../assets/check-icon.png";
Expand Down Expand Up @@ -41,6 +41,8 @@ export const NewUser = () => {
const { t } = useTranslation();
const navigate = useNavigate();

const [openResetConfirmation, setOpenResetConfirmation] = useState(false);

const create = useAppSelector((state) => state.users.create);

const userGroupsTypeState = useAppSelector(
Expand Down Expand Up @@ -78,6 +80,11 @@ export const NewUser = () => {
};
}, [create.hasSucceeded, dispatch, navigate]);

const handleResetConfirmation = () => {
setOpenResetConfirmation(false);
navigate(-1);
};

const handleCheckboxChange = useCallback(
(fieldName: string) => (value: boolean) => {
setFieldValue(fieldName, value);
Expand Down Expand Up @@ -197,12 +204,11 @@ export const NewUser = () => {
</div>
<div className="reset_button">
<Button
dataCy="cancel-form"
type="reset"
variant="text"
disabled={!!create.isLoading}
onClick={() => {
navigate(PATHS.admin_users);
}}
disabled={create.isLoading}
onClick={() => setOpenResetConfirmation(true)}
>
{t("common.cancel")}
</Button>
Expand All @@ -219,6 +225,16 @@ export const NewUser = () => {
}}
handleSecondaryButtonClick={() => ({})}
/>
<ConfirmationDialog
isOpen={openResetConfirmation}
title={t("common.cancel")}
info={t("common.resetform")}
icon={warningIcon}
primaryButtonLabel={t("common.ok")}
secondaryButtonLabel={t("common.discard")}
handlePrimaryButtonClick={handleResetConfirmation}
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
/>
<ConfirmationDialog
isOpen={create.hasFailed}
title={t("errors.internalerror")}
Expand Down
1 change: 1 addition & 0 deletions src/components/accessories/admin/users/newUser/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
display: flex;
margin-top: 25px;
padding: 0px 15px;
gap: 2px;
flex-direction: row-reverse;
@include susy-media($smartphone_small) {
display: block;
Expand Down
89 changes: 45 additions & 44 deletions src/components/accessories/confirmationDialog/styles.scss
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
@import "../../../styles/variables";
@import "../../../../node_modules/susy/sass/susy";

.dialog__title {
width: 100%;
text-align: center;
font-weight: bold;
}

.dialog__icon {
height: 90px;
margin-top: 20px;
display: block;
margin-left: auto;
margin-right: auto;
}

.dialog__info {
margin: 25px 0px 40px;
}

.dialog__divider {
width: 100%;
background-color: $c-grey-light;
height: 0.5px;
}

.dialog__buttonSet {
display: flex;
flex-direction: row-reverse;
margin-bottom: 10px;
@include susy-media($smartphone_small) {
display: block;
}

.submit_button,
.reset_button {
.MuiButton-label {
font-size: smaller;
letter-spacing: 1px;
font-weight: 600;
}
}
}
@import "../../../styles/variables";
@import "../../../../node_modules/susy/sass/susy";

.dialog__title {
width: 100%;
text-align: center;
font-weight: bold;
}

.dialog__icon {
height: 90px;
margin-top: 20px;
display: block;
margin-left: auto;
margin-right: auto;
}

.dialog__info {
margin: 25px 0px 40px;
}

.dialog__divider {
width: 100%;
background-color: $c-grey-light;
height: 0.5px;
}

.dialog__buttonSet {
display: flex;
flex-direction: row-reverse;
margin-bottom: 10px;
gap: 2px;
@include susy-media($smartphone_small) {
display: block;
}

.submit_button,
.reset_button {
.MuiButton-label {
font-size: smaller;
letter-spacing: 1px;
font-weight: 600;
}
}
}

0 comments on commit 382c207

Please sign in to comment.