diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.tsx index 42e68aabde..6d8e16f84e 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.tsx @@ -1,12 +1,17 @@ +import { useQuery } from "@apollo/client"; import Box from "@mui/material/Box"; +import List from "@mui/material/List"; +import ListItem from "@mui/material/ListItem"; import Typography from "@mui/material/Typography"; -import React, { useEffect, useState } from "react"; +import DelayedLoadingIndicator from "components/DelayedLoadingIndicator"; +import ErrorFallback from "components/ErrorFallback"; +import React from "react"; import { FeaturePlaceholder } from "ui/editor/FeaturePlaceholder"; import { useStore } from "../../../lib/store"; import { - fetchSubmittedApplications, SubmissionData, + SUBMITTED_APPLICATIONS_QUERY, } from "./submissionDataTypesAndQueries"; const Submissions: React.FC = () => { @@ -14,23 +19,32 @@ const Submissions: React.FC = () => { state.flowSlug, state.teamSlug, ]); - const [applications, setApplications] = useState(); - const [error, setError] = useState(null); - useEffect(() => { - if (flowSlug && teamSlug) { - fetchSubmittedApplications(flowSlug, teamSlug) - .then((result) => setApplications(result)) - .catch((error) => { - setError(error); - }); - } - }, [flowSlug, teamSlug]); + const { data , loading, error } = useQuery(SUBMITTED_APPLICATIONS_QUERY, { + variables: { service_slug: flowSlug, team_slug: teamSlug }, + skip: !flowSlug || !teamSlug, + }); + + const applications: SubmissionData[] = data?.submissionServicesSummary; - useEffect(() => { - console.log(applications); - console.log(error); - }, [applications, error]); + function SubmissionView(): FCReturn { + if (loading) { + return ; + } + if (error) { + return ; + } + if (applications && applications.length > 0) { + return ( + + {applications.map((application) => { + return {application.sessionId}; + })} + + ); + } + return ; + } return ( @@ -40,9 +54,7 @@ const Submissions: React.FC = () => { View data on the user submitted applications for this service. - - - + {SubmissionView()} ); }; diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/submissionDataTypesAndQueries.ts b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/submissionDataTypesAndQueries.ts index 987adfff0d..29c0a3c336 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/submissionDataTypesAndQueries.ts +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/submissionDataTypesAndQueries.ts @@ -41,35 +41,23 @@ export type SubmissionData = { emailApplications: EmailApplication[] | null; }; -export async function fetchSubmittedApplications( - flowSlug: string, - teamSlug: string, -): Promise { - const { data } = await client.query({ - query: gql` - query SubmittedApplications($service_slug: String!, $team_slug: String!) { - submissionServicesSummary: submission_services_summary( - 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 - } +export const SUBMITTED_APPLICATIONS_QUERY = gql` + query SubmittedApplications($service_slug: String!, $team_slug: String!) { + submissionServicesSummary: submission_services_summary( + where: { + service_slug: { _eq: $service_slug } + team_slug: { _eq: $team_slug } + submitted_at: { _is_null: false } } - `, - variables: { - service_slug: flowSlug, - team_slug: teamSlug, - }, - }); - return data.submissionServicesSummary; -} + 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 + } + } +`;