Skip to content

Commit

Permalink
Merge pull request #130 from microbiomedata/108-add-ability-to-fill-i…
Browse files Browse the repository at this point in the history
…n-study-pi-name-and-orcid-from-logged-in-user-details

Allow user to populate Study PI Name and ORCID iD with user's own info
  • Loading branch information
eecavanna authored Jul 15, 2024
2 parents cc0aef0 + f945cf8 commit d6f0452
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/components/StudyForm/StudyForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import {
IonButton,
IonIcon,
IonInput,
IonSelect,
IonSelectOption,
Expand All @@ -11,6 +12,8 @@ import RequiredMark from "../RequiredMark/RequiredMark";
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 styles from "./StudyForm.module.css";

Expand All @@ -34,6 +37,8 @@ const EMAIL_REGEX =
/^(?!\.)(?!.*\.\.)([A-Z0-9_+-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;

const StudyForm: React.FC<StudyFormProps> = ({ submission, onSave }) => {
const { loggedInUser } = useStore();

const { handleSubmit, control, formState, setValue } =
useForm<SubmissionMetadataCreate>({
defaultValues: submission,
Expand Down Expand Up @@ -120,7 +125,26 @@ const StudyForm: React.FC<StudyFormProps> = ({ submission, onSave }) => {
onIonBlur={field.onBlur}
onIonInput={field.onChange}
{...field}
/>
>
{/* If the user is logged in, show a button they can press to use their name. */}
{loggedInUser !== null ? (
<IonButton
fill={"clear"}
slot={"end"}
title={"Use my name"}
aria-label={"Use my name"}
onClick={() => setValue(field.name, loggedInUser.name)}
disabled={field.value === loggedInUser.name}
>
<IonIcon
slot={"icon-only"}
icon={autoFill}
color={"primary"}
aria-hidden={"true"}
/>
</IonButton>
) : null}
</IonInput>
)}
/>

Expand Down Expand Up @@ -166,7 +190,26 @@ const StudyForm: React.FC<StudyFormProps> = ({ submission, onSave }) => {
onIonBlur={field.onBlur}
onIonInput={field.onChange}
{...field}
/>
>
{/* If the user is logged in, show a button they can press to use their ORCID iD. */}
{loggedInUser !== null ? (
<IonButton
fill={"clear"}
slot={"end"}
title={"Use my ORCID iD"}
aria-label={"Use my ORCID iD"}
onClick={() => setValue(field.name, loggedInUser.orcid)}
disabled={field.value === loggedInUser.orcid}
>
<IonIcon
slot={"icon-only"}
icon={autoFill}
color={"primary"}
aria-hidden={"true"}
/>
</IonButton>
) : null}
</IonInput>
)}
/>
</div>
Expand Down

0 comments on commit d6f0452

Please sign in to comment.