@@ -55,10 +55,9 @@ const EditUser: React.FC<Props> = async ({
},
},
[]
[]
);
);
console.log(rules);
const errors = formProps.formState.errors;
const errors = formProps.formState.errors;
console.log("asdasd")
const fetchUserDetail = async () => {
const fetchUserDetail = async () => {
try {
try {
// fetch user info
// fetch user info
@@ -87,22 +86,16 @@ const EditUser: React.FC<Props> = async ({
fetchUserDetail();
fetchUserDetail();
}, []);
}, []);
// useEffect(() => {
// const thisUser = users.filter((item) => item.id === id)
// formProps.reset({
// username: thisUser[0].username,
// email: thisUser[0].email,
// });
// }, []);
const hasErrorsInTab = (
const hasErrorsInTab = (
tabIndex: number,
tabIndex: number,
errors: FieldErrors<UserResult>
errors: FieldErrors<UserResult>
) => {
) => {
switch (tabIndex) {
switch (tabIndex) {
case 0:
case 0:
console.log("yolo")
return Object.keys(errors).length > 0;
return Object.keys(errors).length > 0;
default:
default:
console.log("yolo")
false;
false;
}
}
};
};
@@ -115,7 +108,7 @@ const EditUser: React.FC<Props> = async ({
async (data) => {
async (data) => {
try {
try {
let haveError = false
let haveError = false
let regex_pw = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8, }$/
let regex_pw = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,20 }$/
let pw = ''
let pw = ''
if (data.password && data.password.length > 0) {
if (data.password && data.password.length > 0) {
pw = data.password
pw = data.password
@@ -132,10 +125,8 @@ const EditUser: React.FC<Props> = async ({
formProps.setError("password", { message: "A combination of uppercase letters, lowercase letters, numbers, and symbols is required.", type: "required" })
formProps.setError("password", { message: "A combination of uppercase letters, lowercase letters, numbers, and symbols is required.", type: "required" })
}
}
}
}
console.log(data);
const userData = {
const userData = {
name: data.name,
name: data.name,
email: '',
locked: false,
locked: false,
addAuthIds: data.addAuthIds || [],
addAuthIds: data.addAuthIds || [],
removeAuthIds: data.removeAuthIds || [],
removeAuthIds: data.removeAuthIds || [],
@@ -145,10 +136,10 @@ const EditUser: React.FC<Props> = async ({
password: "",
password: "",
newPassword: pw
newPassword: pw
}
}
console.log(userData);
if (haveError) {
if (haveError) {
return
return
}
}
console.log("passed")
await editUser(id, userData);
await editUser(id, userData);
if (data.password && data.password.length > 0) {
if (data.password && data.password.length > 0) {
await adminChangePassword(pwData);
await adminChangePassword(pwData);
@@ -204,7 +195,7 @@ const EditUser: React.FC<Props> = async ({
<Tab label={t("User Authority")} iconPosition="end" />
<Tab label={t("User Authority")} iconPosition="end" />
</Tabs>
</Tabs>
</Stack>
</Stack>
{tabIndex == 0 && <UserDetail data={data!} />}
{tabIndex == 0 && <UserDetail />}
{tabIndex === 1 && <AuthAllocation auths={auths!}/>}
{tabIndex === 1 && <AuthAllocation auths={auths!}/>}
<Stack direction="row" justifyContent="flex-end" gap={1}>
<Stack direction="row" justifyContent="flex-end" gap={1}>
<Button
<Button