From e7910aa64dba633c1f0339af904bc5a3d7d7fd5d Mon Sep 17 00:00:00 2001 From: Patrick Kalita Date: Mon, 2 Dec 2024 15:15:02 -0800 Subject: [PATCH] Replace individual autofill buttons on name and ORCID with single PI button --- src/api.ts | 1 + src/components/StudyForm/StudyForm.tsx | 212 ++++++++++++------------- 2 files changed, 101 insertions(+), 112 deletions(-) diff --git a/src/api.ts b/src/api.ts index 9dea07c..f3a2ad3 100644 --- a/src/api.ts +++ b/src/api.ts @@ -165,6 +165,7 @@ export interface User { orcid: string; name: string; is_admin: boolean; + email?: string | null; } interface SubmissionMetadataBase { diff --git a/src/components/StudyForm/StudyForm.tsx b/src/components/StudyForm/StudyForm.tsx index d4e5810..feb8284 100644 --- a/src/components/StudyForm/StudyForm.tsx +++ b/src/components/StudyForm/StudyForm.tsx @@ -1,8 +1,9 @@ import React from "react"; import { IonButton, - IonIcon, IonInput, + IonItem, + IonLabel, IonSelect, IonSelectOption, IonText, @@ -13,7 +14,6 @@ import SectionHeader from "../SectionHeader/SectionHeader"; import { SubmissionMetadataCreate, TEMPLATES } from "../../api"; import { Controller, useForm } from "react-hook-form"; import { useStore } from "../../Store"; -import { colorWand as autoFill } from "ionicons/icons"; import { StepType } from "@reactour/tour"; import styles from "./StudyForm.module.css"; import { useAppTour } from "../AppTourProvider/hooks"; @@ -87,6 +87,17 @@ const StudyForm: React.FC = ({ disabled, }); + const handlePIAutoFill = () => { + if (loggedInUser === null) { + return; + } + setValue("metadata_submission.studyForm.piName", loggedInUser.name); + if (loggedInUser.email) { + setValue("metadata_submission.studyForm.piEmail", loggedInUser.email); + } + setValue("metadata_submission.studyForm.piOrcid", loggedInUser.orcid); + }; + return (
@@ -153,112 +164,89 @@ const StudyForm: React.FC = ({ Principal Investigator -
- ( - - {/* If the user is logged in, show a button they can press to use their name. */} - {loggedInUser !== null ? ( - setValue(field.name, loggedInUser.name)} - disabled={field.value === loggedInUser.name} - > - - - ) : null} - - )} - /> +
+
+ ( + + )} + /> - - EMAIL_REGEX.test(value) || "Not a valid email address", - }, - }} - render={({ field, fieldState }) => ( - -
- Email - -
-
- )} - /> + + EMAIL_REGEX.test(value) || "Not a valid email address", + }, + }} + render={({ field, fieldState }) => ( + +
+ Email + +
+
+ )} + /> - ( - - {/* If the user is logged in, show a button they can press to use their ORCID iD. */} - {loggedInUser !== null ? ( - setValue(field.name, loggedInUser.orcid)} - disabled={field.value === loggedInUser.orcid} - > - - - ) : null} - - )} - /> + ( + + )} + /> +
+ {loggedInUser !== null && ( + + +

I am the Study's Principal Investigator

+
+
+ )}
Environment -
+
= ({ )} /> - - - {formState.isSubmitting ? "Saving" : "Save"} -
+ + + {formState.isSubmitting ? "Saving" : "Save"} + ); };