Skip to content

Commit

Permalink
fix: Active submission prompt persisting past first save
Browse files Browse the repository at this point in the history
Also migrates to Notistack for this specific page
  • Loading branch information
amattu2 committed Jan 22, 2024
1 parent f38fc6c commit 70a74e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/content/organizations/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
OutlinedInput, Select, Stack, Typography,
styled,
} from '@mui/material';
import { useSnackbar } from 'notistack';
import { cloneDeep } from 'lodash';
import { Controller, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import bannerSvg from '../../assets/banner/profile_banner.png';
import profileIcon from '../../assets/icons/organization.svg';
import GenericAlert from '../../components/GenericAlert';
import SuspenseLoader from '../../components/SuspenseLoader';
import {
CREATE_ORG, CreateOrgResp,
Expand Down Expand Up @@ -156,13 +156,13 @@ const inactiveSubmissionStatus: SubmissionStatus[] = ["Completed", "Archived"];
*/
const OrganizationView: FC<Props> = ({ _id }: Props) => {
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();

const [organization, setOrganization] = useState<Organization | null>(null);
const [dataSubmissions, setDataSubmissions] = useState<Partial<Submission>[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [saving, setSaving] = useState<boolean>(false);
const [confirmOpen, setConfirmOpen] = useState<boolean>(false);
const [changesAlert, setChangesAlert] = useState<string>("");

const assignedStudies: string[] = useMemo(() => {
const activeStudies = {};
Expand Down Expand Up @@ -258,7 +258,7 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {

setOrganization(null);
setDataSubmissions(null);
setChangesAlert("This organization has been successfully added.");
enqueueSnackbar("This organization has been successfully added.", { variant: "default" });
reset();
} else {
const { data: d, errors } = await editOrganization({ variables: { orgID: organization._id, ...variables, } })
Expand All @@ -270,12 +270,12 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {
return;
}

setChangesAlert("All changes have been saved");
enqueueSnackbar("All changes have been saved.", { variant: "default" });
setFormValues(data);
setOrganization((prev: Organization) => ({ ...prev, studies: d.editOrganization.studies }));
}

setError(null);
setTimeout(() => setChangesAlert(""), 10000);
};

/**
Expand Down Expand Up @@ -331,11 +331,6 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {

return (
<>
<GenericAlert open={!!changesAlert} key="organization-changes-alert">
<span>
{changesAlert}
</span>
</GenericAlert>
<StyledBanner />
<StyledContainer maxWidth="lg">
<Stack
Expand Down
12 changes: 11 additions & 1 deletion src/graphql/editOrganization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ export const mutation = gql`
mutation editOrganization($orgID: ID!, $name: String, $conciergeID: String, $studies: [ApprovedStudyInput], $status: String) {
editOrganization(orgID: $orgID, name: $name, conciergeID: $conciergeID, studies: $studies, status: $status) {
_id
name
status
conciergeID
conciergeName
studies {
studyName
studyAbbreviation
}
createdAt
updateAt
}
}
`;

export type Response = {
editOrganization: Pick<Organization, "_id">;
editOrganization: Organization;
};
2 changes: 2 additions & 0 deletions src/graphql/getOrganization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const query = gql`
studyName
studyAbbreviation
}
createdAt
updateAt
}
listSubmissions(first: -1, offset: 0, orderBy: "updatedAt", sortDirection: "ASC", organization: $organization, status: "All") {
submissions {
Expand Down

0 comments on commit 70a74e5

Please sign in to comment.