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

feat: query submission_services_summary and log result #2885

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import React from "react";
import React, { useEffect, useState } from "react";
import { FeaturePlaceholder } from "ui/editor/FeaturePlaceholder";

import { useStore } from "../../../lib/store";
import {
fetchSubmittedApplications,
SubmissionData,
} from "./submissionDataTypesAndQueries";

const Submissions: React.FC = () => {
const flowSlug = useStore.getState().flowSlug;
const teamSlug = useStore.getState().teamSlug;
DafyddLlyr marked this conversation as resolved.
Show resolved Hide resolved
const [applications, setApplications] = useState<SubmissionData[]>();
const [error, setError] = useState(null);

useEffect(() => {
if (flowSlug && teamSlug) {
fetchSubmittedApplications(flowSlug, teamSlug)
.then((result) => setApplications(result.submission_services_summary))
.catch((error) => {
setError(error);
});
}
}, [flowSlug, teamSlug]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data fetching from within components is probably not handled very consistently currently in the application. I would think most data queries are handled at the route level, set to the store, and then updated from there.

In this instance, I'd recommend you take a look at the useQuery() hook which allows access to nice loading and error variables which can be used by the UI - this might allow you to simplify some of this code.


useEffect(() => {
console.log(applications);
console.log(error);
}, [applications, error]);

return (
<Box>
<Typography variant="h2" component="h3" gutterBottom>
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than be in the lib folder I've abstracted this into it's own file.

This was for readability in the Submission but also because I think it'll make test setup much easier later as the query can be more easily mocked with this approach.

Open to feedback on this though!

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import gql from "graphql-tag";
import { client } from "lib/graphql";

type PaymentRequest = {
id: string;
createdAt: string;
paidAt: string;
govPaymentId: string;
};

type PaymentStatus = {
govPaymentId: string;
createdAt: string;
status: string;
};

type BopsApplication = {
id: string;
submittedAt: string;
destinationUrl: string;
};

type EmailApplication = {
id: string;
recipient: string;
submittedAt: string;
};

type UniformApplication = {
id: string;
submittedAt: string;
};

export type SubmissionData = {
DafyddLlyr marked this conversation as resolved.
Show resolved Hide resolved
sessionId: string;
submittedAt: Date | string;
paymentRequests: PaymentRequest[] | null;
paymentStatus: PaymentStatus[] | null;
bopsApplications: BopsApplication[] | null;
uniformApplications: UniformApplication[] | null;
emailApplications: EmailApplication[] | null;
};

export async function fetchSubmittedApplications(
flowSlug: string,
teamSlug: string,
) {
const { data } = await client.query({
query: gql`
query SubmittedApplications($service_slug: String!, $team_slug: String!) {
submission_services_summary(
DafyddLlyr marked this conversation as resolved.
Show resolved Hide resolved
where: {
service_slug: { _eq: $service_slug }
team_slug: { _eq: $team_slug }
submitted_at: { _is_null: false }
}
order_by: { submitted_at: desc }
) {
sessionId: session_id
submittedAt: submitted_at
paymentRequests: payment_requests
paymentStatus: payment_status
bopsApplications: bops_applications
uniformApplications: uniform_applications
emailApplications: email_applications
Mike-Heneghan marked this conversation as resolved.
Show resolved Hide resolved
}
}
`,
variables: {
service_slug: flowSlug,
team_slug: teamSlug,
},
});
return data;
}
Loading