Skip to content

Commit

Permalink
fixed issue with draft data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
al-rosenthal committed Aug 28, 2023
1 parent e72411f commit c1aa941
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
8 changes: 8 additions & 0 deletions app/src/features/projects/components/ProjectUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const ProjectUserForm: React.FC<IProjectUser> = (props) => {
useEffect(() => {
props.users.forEach((user, index) => {
setFieldValue(`participants[${index}].system_user_id`, user.system_user_id);
setFieldValue(`participants[${index}].display_name`, user.display_name);
setFieldValue(`participants[${index}].email`, user.email);
setFieldValue(`participants[${index}].agency`, user.agency);
setFieldValue(`participants[${index}].identity_source`, user.identity_source);
setFieldValue(`participants[${index}].project_role_names`, (user as IGetProjectParticipant).project_role_names);
});
setSelectedUsers(props.users);
Expand All @@ -70,6 +74,10 @@ const ProjectUserForm: React.FC<IProjectUser> = (props) => {

setFieldValue(`participants[${selectedUsers.length - 1}]`, {
system_user_id: user.system_user_id,
display_name: user.display_name,
email: user.email,
agency: user.agency,
identity_source: user.identity_source,
project_role_names: []
});
clearErrors();
Expand Down
33 changes: 22 additions & 11 deletions app/src/features/projects/create/CreateProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,27 @@ const CreateProjectForm: React.FC<ICreateProjectForm> = (props) => {

const { keycloakWrapper } = useContext(AuthStateContext);

const getLoggedInUserAsParticipant = (): IGetProjectParticipant => {
const loggedInUser = keycloakWrapper?.user;
return {
system_user_id: loggedInUser?.system_user_id,
display_name: loggedInUser?.display_name,
email: loggedInUser?.email,
agency: loggedInUser?.agency,
identity_source: loggedInUser?.identity_source,
project_role_names: [PROJECT_ROLE.COORDINATOR]
} as IGetProjectParticipant;
const getProjectParticipants = (): IGetProjectParticipant[] => {
let participants: IGetProjectParticipant[] = [];

// load initial values from draft webform
if (props.initialValues?.participants) {
participants = props.initialValues?.participants as IGetProjectParticipant[];
} else {
// this is a fresh form and the logged in user needs to be added as a participant
const loggedInUser = keycloakWrapper?.user;
participants = [
{
system_user_id: loggedInUser?.system_user_id,
display_name: loggedInUser?.display_name,
email: loggedInUser?.email,
agency: loggedInUser?.agency,
identity_source: loggedInUser?.identity_source,
project_role_names: [PROJECT_ROLE.COORDINATOR]
} as IGetProjectParticipant
];
}
return participants;
};

return (
Expand Down Expand Up @@ -182,7 +193,7 @@ const CreateProjectForm: React.FC<ICreateProjectForm> = (props) => {
<HorizontalSplitFormComponent
title="Team Members"
summary="Specify team members and their associated role for this project."
component={<ProjectUserForm users={[getLoggedInUserAsParticipant()]} roles={codes.project_roles} />}
component={<ProjectUserForm users={getProjectParticipants()} roles={codes.project_roles} />}
/>

<Divider className={classes.sectionDivider} />
Expand Down
2 changes: 0 additions & 2 deletions app/src/features/projects/edit/EditProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const EditProjectForm: React.FC<IEditProjectForm> = (props) => {
enableReinitialize={true}
onSubmit={handleSubmit}>
<>
{/* <ScrollToFormikError fieldOrder={Object.keys(initialProjectFieldData)} /> */}

<HorizontalSplitFormComponent
title="General Information"
summary="Enter general information, objectives and timelines for the project."
Expand Down

0 comments on commit c1aa941

Please sign in to comment.