Skip to content

Commit

Permalink
Merge pull request #66 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 4, 2025
2 parents 2b6b9c7 + 54f0fde commit 89a7ff2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/components/CippFormPages/CippAddEditUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { CippFormLicenseSelector } from "/src/components/CippComponents/CippForm
import Grid from "@mui/material/Grid";
import { ApiGetCall } from "../../api/ApiCall";
import { useSettings } from "../../hooks/use-settings";
import { useWatch } from "react-hook-form";
import { useEffect } from "react";

const CippAddEditUser = (props) => {
const { formControl, userSettingsDefaults, formType = "add" } = props;
Expand All @@ -16,6 +18,15 @@ const CippAddEditUser = (props) => {
url: "/api/ListExtensionsConfig",
queryKey: "ListExtensionsConfig",
});

const watcher = useWatch({ control: formControl.control });
useEffect(() => {
//if watch.firstname changes, and watch.lastname changes, set displayname to firstname + lastname
if (watcher.givenName && watcher.surname && formType === "add") {
formControl.setValue("displayName", `${watcher.givenName} ${watcher.surname}`);
}
}, [watcher.givenName, watcher.surname]);

return (
<Grid container spacing={2}>
<Grid item xs={12} md={6}>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/identity/administration/users/add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Page = () => {
const userSettingsDefaults = useSettings();

const formControl = useForm({
mode: "onChange",
mode: "onBlur",
defaultValues: {
tenantFilter: userSettingsDefaults.currentTenant,
usageLocation: userSettingsDefaults.usageLocation,
Expand All @@ -36,6 +36,7 @@ const Page = () => {
newFields.usageLocation = { label: usageLocation, value: usageLocation };
}
newFields.tenantFilter = userSettingsDefaults.currentTenant;

formControl.reset(newFields);
}
}, [formValues]);
Expand Down
11 changes: 10 additions & 1 deletion src/pages/identity/administration/users/user/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Page = () => {
});

const formControl = useForm({
mode: "onChange",
mode: "onBlur",
defaultValues: {
tenantFilter: userSettingsDefaults.currentTenant,
},
Expand All @@ -34,8 +34,17 @@ const Page = () => {
useEffect(() => {
if (userRequest.isSuccess) {
const user = userRequest.data?.[0];
//if we have userSettingsDefaults.userAttributes set, grab the .label from each userSsettingsDefaults, then set defaultAttributes.${label}.value to user.${label}
let defaultAttributes = {};
if (userSettingsDefaults.userAttributes) {
userSettingsDefaults.userAttributes.forEach((attribute) => {
defaultAttributes[attribute.label] = { Value: user?.[attribute.label] };
});
}
console.log(defaultAttributes);
formControl.reset({
...user,
defaultAttributes: defaultAttributes,
tenantFilter: userSettingsDefaults.currentTenant,
licenses: user.assignedLicenses.map((license) => ({
label: getCippLicenseTranslation([license]),
Expand Down

0 comments on commit 89a7ff2

Please sign in to comment.