-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeneralSettings.tsx
86 lines (81 loc) · 2.68 KB
/
GeneralSettings.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* eslint-disable */
import React, { useEffect, useState } from "react";
import { useAppDispatch, useAppSelector } from "../../store/store";
import {
fetchPasswordExpiration,
updateUserPasswordExpiration,
} from "../../store/features/admin/adminSlice";
import CircularProgress from "@mui/material/CircularProgress";
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
import { Bars } from "react-loader-spinner";
import { LinearProgress } from "@mui/material";
export const GeneralSettings = () => {
const dispatch = useAppDispatch();
const { users, isLoading, passwordExpiration } = useAppSelector(
(state) => state?.admin
);
const [minutes, setMinutes] = useState(passwordExpiration);
const [isDisabled, setIsDisabled] = useState(true);
const [isEdit, setIsEdit] = useState(true);
useEffect(() => {
dispatch(fetchPasswordExpiration());
setMinutes(passwordExpiration);
}, [dispatch, passwordExpiration]);
const handleMinutesChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setMinutes(Number(e.target.value));
};
const handleSavePasswordExpiration = () => {
if (minutes) {
dispatch(updateUserPasswordExpiration({ minutes }));
}
setIsDisabled(true);
setIsEdit(true);
};
return (
<>
<div className="section-content">
{isLoading && (
<div className="table__spinner">
<Box sx={{ width: "100%" }}>
<LinearProgress
sx={{
backgroundColor: "#fff",
"& .MuiLinearProgress-bar": {
backgroundColor: "#ff8a46",
},
}}
/>
</Box>
</div>
)}
<div className="password_exp">
<div className="form-group">
<label htmlFor="password">Password Expiration Time</label>
<input
type="text"
id="password"
value={minutes}
onChange={handleMinutesChange}
disabled={isDisabled}
onFocus={() => setIsEdit(false)}
placeholder="Enter password expiration period in minutes"
/>
</div>
{isEdit ? (
<button
className="btn"
onClick={() => setIsDisabled(!isDisabled)}
>
Edit
</button>
) : (
<button className="btn" onClick={handleSavePasswordExpiration}>
Save
</button>
)}
</div>
</div>
</>
);
};