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

fix: Study removal prompt persisting past first save #268

Merged
merged 3 commits into from
Jan 23, 2024
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
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