Skip to content

Commit

Permalink
feat: Remove form creation (#2060)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagnusHafstad authored Aug 7, 2024
2 parents e5947ad + c333294 commit b7ac878
Showing 1 changed file with 3 additions and 52 deletions.
55 changes: 3 additions & 52 deletions frontend/src/pages/orgs/[orgId]/listings/[listingId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation, useQuery } from "@apollo/client";
import { useQuery } from "@apollo/client";
import { ArrowBack } from "@mui/icons-material";
import { Box, Button, Card, CardContent, Container, Grid, Tab, Tabs, Typography } from "@mui/material";
import { useRouter } from "next/router";
Expand All @@ -8,12 +8,7 @@ import { Link } from "@/components";
import { EditForm } from "@/components/pages/forms/formAdmin/EditForm";
import { FormResponse } from "@/components/pages/forms/formAdmin/FormResponse";
import { OrganizationListing } from "@/components/pages/listings/organization/OrganizationListing";
import {
CreateFormDocument,
FormWithAllResponsesFragmentDoc,
ListingWithResponsesDocument,
ResponseFragment,
} from "@/generated/graphql";
import { ListingWithResponsesDocument, ResponseFragment } from "@/generated/graphql";
import { Layout, RootStyle } from "@/layouts/Layout";
import { NextPageWithLayout } from "@/lib/next";

Expand All @@ -30,42 +25,6 @@ const ListingAdminPage: NextPageWithLayout = () => {
skip: !listingId,
});

// mutation to create a new form
const [createForm] = useMutation(CreateFormDocument, {
// updates the cache so the new form can show instantly
update: (cache, { data }) => {
const newForm = data?.createForm?.form;
if (newForm) {
cache.modify({
id: `ListingType:${listingId}`,
fields: {
form(_, { INVALIDATE }) {
const newRef = cache.writeFragment({
data: newForm,
fragment: FormWithAllResponsesFragmentDoc,
fragmentName: "FormWithAllResponses",
});
if (newRef) return newRef;
return INVALIDATE;
},
},
});
}
},
});

const onCreateFormClick = () => {
const listing = data?.listing;
if (listing) {
createForm({
variables: {
formData: { name: `Søknad: ${listing.title}`, description: "", organizationId: orgId as string },
listingId: listing.id,
},
});
}
};

if (loading) return <p>Loading...</p>;
if (error) return <p>Error</p>;

Expand Down Expand Up @@ -143,15 +102,7 @@ const ListingAdminPage: NextPageWithLayout = () => {
<Grid item>
<OrganizationListing listing={data.listing} />
</Grid>
<Grid item>
{data.listing.form ? (
<EditForm form={data.listing.form} />
) : (
<Button fullWidth variant="contained" color="primary" onClick={onCreateFormClick}>
Lag søknad
</Button>
)}
</Grid>
<Grid item>{data.listing.form ? <EditForm form={data.listing.form} /> : <></>}</Grid>
</Grid>
) : (
<>{data.listing.form && <FormResponse response={selectedView} form={data.listing.form} />}</>
Expand Down

0 comments on commit b7ac878

Please sign in to comment.