Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRDCDH-2184 Fix missing required asterisks #588

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/components/StyledFormComponents/StyledAsterisk.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { forwardRef } from "react";
import { styled } from "@mui/material";

const Asterisk = styled("span")(() => ({
const StyledAsterisk = styled("span")(() => ({
color: "#C93F08",
marginLeft: "2px",
fontWeight: 700,
Expand All @@ -9,6 +10,12 @@ const Asterisk = styled("span")(() => ({
lineHeight: "18.8px",
}));

const StyledAsterisk = () => <Asterisk>*</Asterisk>;
const Asterisk = forwardRef<HTMLSpanElement, React.HTMLAttributes<HTMLSpanElement>>(
(props, ref) => (
<StyledAsterisk ref={ref} {...props}>
*
</StyledAsterisk>
)
);

export default StyledAsterisk;
export default Asterisk;
57 changes: 44 additions & 13 deletions src/content/users/ProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import {
UpdateMyUserInput,
UpdateMyUserResp,
} from "../../graphql";
import { formatFullStudyName, formatIDP, formatStudySelectionValue } from "../../utils";
import { formatFullStudyName, formatIDP, formatStudySelectionValue, Logger } from "../../utils";
import { DataCommons } from "../../config/DataCommons";
import usePageTitle from "../../hooks/usePageTitle";
import { useSearchParamsContext } from "../../components/Contexts/SearchParamsContext";
import BaseSelect from "../../components/StyledFormComponents/StyledSelect";
import BaseOutlinedInput from "../../components/StyledFormComponents/StyledOutlinedInput";
import BaseAutocomplete from "../../components/StyledFormComponents/StyledAutocomplete";
import BaseAsterisk from "../../components/StyledFormComponents/StyledAsterisk";
import useProfileFields, { VisibleFieldState } from "../../hooks/useProfileFields";
import AccessRequest from "../../components/AccessRequest";
import PermissionPanel from "../../components/PermissionPanel";
Expand Down Expand Up @@ -113,8 +114,8 @@ const StyledField = styled("div", { shouldForwardProp: (p) => p !== "visible" })
const StyledLabel = styled("span")({
color: "#356AAD",
fontWeight: "700",
marginRight: "40px",
minWidth: "127px",
marginRight: "30px",
minWidth: "137px",
});

const BaseInputStyling = {
Expand Down Expand Up @@ -151,6 +152,12 @@ const StyledTag = styled("div")({
paddingLeft: "12px",
});

const StyledAsterisk = styled(BaseAsterisk, { shouldForwardProp: (p) => p !== "visible" })<{
visible?: boolean;
}>(({ visible = true }) => ({
display: visible ? undefined : "none",
}));

/**
* User Profile View Component
*
Expand Down Expand Up @@ -251,7 +258,8 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
setSaving(false);

if (errors || !d?.updateMyUser) {
enqueueSnackbar(errors || "Unable to save profile changes", { variant: "error" });
Logger.error("ProfileView: Error from API", errors);
enqueueSnackbar("Unable to save profile changes", { variant: "error" });
return;
}

Expand All @@ -272,7 +280,8 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
setSaving(false);

if (errors || !d?.editUser) {
enqueueSnackbar(errors || "Unable to save user profile changes", { variant: "error" });
Logger.error("ProfileView: Error from API", errors);
enqueueSnackbar("Unable to save user profile changes", { variant: "error" });
return;
}

Expand Down Expand Up @@ -395,7 +404,6 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
<StyledProfileIcon>
<img src={profileIcon} alt="profile icon" />
</StyledProfileIcon>

<StyledContentStack
direction="column"
justifyContent="center"
Expand All @@ -421,7 +429,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
{user.email}
</StyledField>
<StyledField>
<StyledLabel id="firstNameLabel">First name</StyledLabel>
<StyledLabel id="firstNameLabel">
First name
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.firstName)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.firstName) ? (
<StyledTextField
{...register("firstName", {
Expand All @@ -438,7 +449,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
)}
</StyledField>
<StyledField>
<StyledLabel id="lastNameLabel">Last name</StyledLabel>
<StyledLabel id="lastNameLabel">
Last name
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.lastName)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.lastName) ? (
<StyledTextField
{...register("lastName", {
Expand All @@ -455,7 +469,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
)}
</StyledField>
<StyledField>
<StyledLabel id="userRoleLabel">Role</StyledLabel>
<StyledLabel id="userRoleLabel">
Role
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.role)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.role) ? (
<Controller
name="role"
Expand Down Expand Up @@ -485,7 +502,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
)}
</StyledField>
<StyledField visible={fieldset.studies !== "HIDDEN"}>
<StyledLabel id="userStudies">Studies</StyledLabel>
<StyledLabel id="userStudies">
Studies
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.studies)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.studies) ? (
<Controller
name="studies"
Expand All @@ -498,7 +518,11 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
<TextField
{...params}
placeholder={studiesField?.length > 0 ? undefined : "Select studies"}
inputProps={{ "aria-labelledby": "userStudies", ...inputProps }}
inputProps={{
"aria-labelledby": "userStudies",
required: studiesField.length === 0,
...inputProps,
}}
onBlur={sortStudyOptions}
/>
)}
Expand Down Expand Up @@ -526,7 +550,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
) : null}
</StyledField>
<StyledField>
<StyledLabel id="userStatusLabel">Account Status</StyledLabel>
<StyledLabel id="userStatusLabel">
Account Status
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.userStatus)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.userStatus) ? (
<Controller
name="userStatus"
Expand All @@ -549,7 +576,10 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
)}
</StyledField>
<StyledField visible={fieldset.dataCommons !== "HIDDEN"}>
<StyledLabel id="userDataCommons">Data Commons</StyledLabel>
<StyledLabel id="userDataCommons">
Data Commons
<StyledAsterisk visible={VisibleFieldState.includes(fieldset.dataCommons)} />
</StyledLabel>
{VisibleFieldState.includes(fieldset.dataCommons) ? (
<Controller
name="dataCommons"
Expand All @@ -563,6 +593,7 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
disabled={fieldset.dataCommons === "DISABLED"}
MenuProps={{ disablePortal: true }}
inputProps={{ "aria-labelledby": "userDataCommons" }}
required
multiple
>
{DataCommons.map((dc) => (
Expand Down
Loading