Skip to content

Commit 4733480

Browse files
SteveGT96SteveGT96
andauthored
fix(OH2-440): Add cancel action on user/group creation/update (#705)
Co-authored-by: SteveGT96 <steve.tsala@intesys.it>
1 parent b53066b commit 4733480

File tree

9 files changed

+136
-69
lines changed

9 files changed

+136
-69
lines changed

src/components/accessories/admin/users/editGroup/EditGroup.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useParams } from "react-router";
66
import { useNavigate } from "react-router-dom";
77

88
import checkIcon from "../../../../../assets/check-icon.png";
9+
import warningIcon from "../../../../../assets/warning-icon.png";
910
import Button from "../../../button/Button";
1011
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
1112
import InfoBox from "../../../infoBox/InfoBox";
@@ -42,6 +43,8 @@ export const EditGroup = () => {
4243
const { id } = useParams();
4344
const canUpdatePermissions = usePermission("grouppermission.update");
4445

46+
const [openResetConfirmation, setOpenResetConfirmation] = useState(false);
47+
4548
const update = useAppSelector((state) => state.usergroups.update);
4649
const permissions = useAppSelector((state) => state.permissions.getAll);
4750
const group = useAppSelector((state) => state.usergroups.currentGroup);
@@ -130,9 +133,9 @@ export const EditGroup = () => {
130133
};
131134
}, []);
132135

133-
const handleFormReset = () => {
134-
resetForm();
135-
setGroupPermissions(group.data?.permissions ?? []);
136+
const handleResetConfirmation = () => {
137+
setOpenResetConfirmation(false);
138+
navigate(-1);
136139
};
137140

138141
const handleCheckboxChange = useCallback(
@@ -262,16 +265,27 @@ export const EditGroup = () => {
262265
</div>
263266
<div className="reset_button">
264267
<Button
268+
dataCy="cancel-form"
265269
type="reset"
266270
variant="text"
267-
disabled={!!update.isLoading || !(dirty || dirtyPermissions)}
268-
onClick={handleFormReset}
271+
disabled={update.isLoading}
272+
onClick={() => setOpenResetConfirmation(true)}
269273
>
270-
{t("common.reset")}
274+
{t("common.cancel")}
271275
</Button>
272276
</div>
273277
</div>
274278
</form>
279+
<ConfirmationDialog
280+
isOpen={openResetConfirmation}
281+
title={t("common.cancel")}
282+
info={t("common.resetform")}
283+
icon={warningIcon}
284+
primaryButtonLabel={t("common.ok")}
285+
secondaryButtonLabel={t("common.discard")}
286+
handlePrimaryButtonClick={handleResetConfirmation}
287+
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
288+
/>
275289
<ConfirmationDialog
276290
isOpen={update.hasSucceeded}
277291
title={t("user.groupUpdated")}

src/components/accessories/admin/users/editGroup/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
margin-top: 25px;
6363
padding: 0px 15px;
6464
flex-direction: row-reverse;
65+
gap: 2px;
6566
@include susy-media($smartphone_small) {
6667
display: block;
6768
}

src/components/accessories/admin/users/editUser/EditUserForm.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
TextField as MuiTextField,
66
} from "@mui/material";
77
import { useFormik } from "formik";
8-
import React, { ReactNode, useCallback } from "react";
8+
import React, { ReactNode, useCallback, useState } from "react";
99
import { useTranslation } from "react-i18next";
1010
import { useNavigate } from "react-router-dom";
1111

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

1414
import checkIcon from "../../../../../assets/check-icon.png";
15+
import warningIcon from "../../../../../assets/warning-icon.png";
1516
import Button from "../../../button/Button";
1617
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
1718
import InfoBox from "../../../infoBox/InfoBox";
@@ -44,6 +45,8 @@ export const EditUserForm = ({
4445
const { t } = useTranslation();
4546
const navigate = useNavigate();
4647

48+
const [openResetConfirmation, setOpenResetConfirmation] = useState(false);
49+
4750
const handleFormSubmit = (values: UserDTO & { passwd2: string }) => {
4851
const { passwd2, ...userDTO } = values;
4952
if (userDTO.passwd === undefined) {
@@ -59,7 +62,6 @@ export const EditUserForm = ({
5962
getFieldProps,
6063
isValid,
6164
dirty,
62-
resetForm,
6365
errors,
6466
touched,
6567
values,
@@ -71,6 +73,11 @@ export const EditUserForm = ({
7173
onSubmit: handleFormSubmit,
7274
});
7375

76+
const handleResetConfirmation = () => {
77+
setOpenResetConfirmation(false);
78+
navigate(-1);
79+
};
80+
7481
const handleCheckboxChange = useCallback(
7582
(fieldName: string) => (value: boolean) => {
7683
setFieldValue(fieldName, value);
@@ -192,18 +199,27 @@ export const EditUserForm = ({
192199
</div>
193200
<div className="reset_button">
194201
<Button
202+
dataCy="cancel-form"
195203
type="reset"
196204
variant="text"
197-
disabled={!!isLoading || !dirty}
198-
onClick={async () => {
199-
resetForm();
200-
}}
205+
disabled={isLoading}
206+
onClick={() => setOpenResetConfirmation(true)}
201207
>
202-
{t("common.reset")}
208+
{t("common.cancel")}
203209
</Button>
204210
</div>
205211
</div>
206212
</form>
213+
<ConfirmationDialog
214+
isOpen={openResetConfirmation}
215+
title={t("common.cancel")}
216+
info={t("common.resetform")}
217+
icon={warningIcon}
218+
primaryButtonLabel={t("common.ok")}
219+
secondaryButtonLabel={t("common.discard")}
220+
handlePrimaryButtonClick={handleResetConfirmation}
221+
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
222+
/>
207223
<ConfirmationDialog
208224
isOpen={hasSucceeded}
209225
title={t("user.updatedSuccessTitle")}

src/components/accessories/admin/users/editUser/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
display: flex;
6262
margin-top: 25px;
6363
padding: 0px 15px;
64+
gap: 2px;
6465
flex-direction: row-reverse;
6566
@include susy-media($smartphone_small) {
6667
display: block;

src/components/accessories/admin/users/newGroup/NewGroup.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useFormik } from "formik";
22
import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
3-
import React, { useCallback, useEffect } from "react";
3+
import React, { useCallback, useEffect, useState } from "react";
44
import { useTranslation } from "react-i18next";
55
import { useNavigate } from "react-router-dom";
66

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

36+
const [openResetConfirmation, setOpenResetConfirmation] = useState(false);
37+
3538
const create = useAppSelector((state) => state.usergroups.create);
3639

3740
const {
@@ -40,7 +43,6 @@ export const NewGroup = () => {
4043
getFieldProps,
4144
isValid,
4245
dirty,
43-
resetForm,
4446
errors,
4547
touched,
4648
values,
@@ -59,6 +61,11 @@ export const NewGroup = () => {
5961
};
6062
}, [dispatch]);
6163

64+
const handleResetConfirmation = () => {
65+
setOpenResetConfirmation(false);
66+
navigate(-1);
67+
};
68+
6269
const handleCheckboxChange = useCallback(
6370
(fieldName: string) => (value: boolean) => {
6471
setFieldValue(fieldName, value);
@@ -123,18 +130,27 @@ export const NewGroup = () => {
123130
</div>
124131
<div className="reset_button">
125132
<Button
133+
dataCy="cancel-form"
126134
type="reset"
127135
variant="text"
128-
disabled={!!create.isLoading || !dirty}
129-
onClick={async () => {
130-
resetForm();
131-
}}
136+
disabled={create.isLoading}
137+
onClick={() => setOpenResetConfirmation(true)}
132138
>
133-
{t("common.reset")}
139+
{t("common.cancel")}
134140
</Button>
135141
</div>
136142
</div>
137143
</form>
144+
<ConfirmationDialog
145+
isOpen={openResetConfirmation}
146+
title={t("common.cancel")}
147+
info={t("common.resetform")}
148+
icon={warningIcon}
149+
primaryButtonLabel={t("common.ok")}
150+
secondaryButtonLabel={t("common.discard")}
151+
handlePrimaryButtonClick={handleResetConfirmation}
152+
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
153+
/>
138154
<ConfirmationDialog
139155
isOpen={create.hasSucceeded}
140156
title={t("user.groupCreated")}

src/components/accessories/admin/users/newGroup/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
display: flex;
6262
margin-top: 25px;
6363
padding: 0px 15px;
64+
gap: 2px;
6465
flex-direction: row-reverse;
6566
@include susy-media($smartphone_small) {
6667
display: block;

src/components/accessories/admin/users/newUser/NewUser.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "@mui/material";
77
import { useFormik } from "formik";
88
import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
9-
import React, { ReactNode, useCallback, useEffect } from "react";
9+
import React, { ReactNode, useCallback, useEffect, useState } from "react";
1010
import { useTranslation } from "react-i18next";
1111
import { useNavigate } from "react-router-dom";
1212
import checkIcon from "../../../../../assets/check-icon.png";
@@ -41,6 +41,8 @@ export const NewUser = () => {
4141
const { t } = useTranslation();
4242
const navigate = useNavigate();
4343

44+
const [openResetConfirmation, setOpenResetConfirmation] = useState(false);
45+
4446
const create = useAppSelector((state) => state.users.create);
4547

4648
const userGroupsTypeState = useAppSelector(
@@ -78,6 +80,11 @@ export const NewUser = () => {
7880
};
7981
}, [create.hasSucceeded, dispatch, navigate]);
8082

83+
const handleResetConfirmation = () => {
84+
setOpenResetConfirmation(false);
85+
navigate(-1);
86+
};
87+
8188
const handleCheckboxChange = useCallback(
8289
(fieldName: string) => (value: boolean) => {
8390
setFieldValue(fieldName, value);
@@ -200,12 +207,11 @@ export const NewUser = () => {
200207
</div>
201208
<div className="reset_button">
202209
<Button
210+
dataCy="cancel-form"
203211
type="reset"
204212
variant="text"
205-
disabled={!!create.isLoading}
206-
onClick={() => {
207-
navigate(PATHS.admin_users);
208-
}}
213+
disabled={create.isLoading}
214+
onClick={() => setOpenResetConfirmation(true)}
209215
>
210216
{t("common.cancel")}
211217
</Button>
@@ -222,6 +228,16 @@ export const NewUser = () => {
222228
}}
223229
handleSecondaryButtonClick={() => ({})}
224230
/>
231+
<ConfirmationDialog
232+
isOpen={openResetConfirmation}
233+
title={t("common.cancel")}
234+
info={t("common.resetform")}
235+
icon={warningIcon}
236+
primaryButtonLabel={t("common.ok")}
237+
secondaryButtonLabel={t("common.discard")}
238+
handlePrimaryButtonClick={handleResetConfirmation}
239+
handleSecondaryButtonClick={() => setOpenResetConfirmation(false)}
240+
/>
225241
<ConfirmationDialog
226242
isOpen={create.hasFailed}
227243
title={t("errors.internalerror")}

src/components/accessories/admin/users/newUser/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
display: flex;
6262
margin-top: 25px;
6363
padding: 0px 15px;
64+
gap: 2px;
6465
flex-direction: row-reverse;
6566
@include susy-media($smartphone_small) {
6667
display: block;
Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
@import "../../../styles/variables";
2-
@import "../../../../node_modules/susy/sass/susy";
3-
4-
.dialog__title {
5-
width: 100%;
6-
text-align: center;
7-
font-weight: bold;
8-
}
9-
10-
.dialog__icon {
11-
height: 90px;
12-
margin-top: 20px;
13-
display: block;
14-
margin-left: auto;
15-
margin-right: auto;
16-
}
17-
18-
.dialog__info {
19-
margin: 25px 0px 40px;
20-
}
21-
22-
.dialog__divider {
23-
width: 100%;
24-
background-color: $c-grey-light;
25-
height: 0.5px;
26-
}
27-
28-
.dialog__buttonSet {
29-
display: flex;
30-
flex-direction: row-reverse;
31-
margin-bottom: 10px;
32-
@include susy-media($smartphone_small) {
33-
display: block;
34-
}
35-
36-
.submit_button,
37-
.reset_button {
38-
.MuiButton-label {
39-
font-size: smaller;
40-
letter-spacing: 1px;
41-
font-weight: 600;
42-
}
43-
}
44-
}
1+
@import "../../../styles/variables";
2+
@import "../../../../node_modules/susy/sass/susy";
3+
4+
.dialog__title {
5+
width: 100%;
6+
text-align: center;
7+
font-weight: bold;
8+
}
9+
10+
.dialog__icon {
11+
height: 90px;
12+
margin-top: 20px;
13+
display: block;
14+
margin-left: auto;
15+
margin-right: auto;
16+
}
17+
18+
.dialog__info {
19+
margin: 25px 0px 40px;
20+
}
21+
22+
.dialog__divider {
23+
width: 100%;
24+
background-color: $c-grey-light;
25+
height: 0.5px;
26+
}
27+
28+
.dialog__buttonSet {
29+
display: flex;
30+
flex-direction: row-reverse;
31+
margin-bottom: 10px;
32+
gap: 2px;
33+
@include susy-media($smartphone_small) {
34+
display: block;
35+
}
36+
37+
.submit_button,
38+
.reset_button {
39+
.MuiButton-label {
40+
font-size: smaller;
41+
letter-spacing: 1px;
42+
font-weight: 600;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)