-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restructure and use
useQuery
- As per: #2885 (comment) - Separating concerns for readability / ease fo testing
- Loading branch information
1 parent
cc2eb17
commit 30b4c0c
Showing
4 changed files
with
143 additions
and
99 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import List from "@mui/material/List"; | ||
import ListItem from "@mui/material/ListItem"; | ||
import Typography from "@mui/material/Typography"; | ||
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator"; | ||
import ErrorFallback from "components/ErrorFallback"; | ||
import React from "react"; | ||
|
||
import { SubmissionData } from "./submissionData"; | ||
|
||
interface SubmissionsViewProps { | ||
applications: SubmissionData[]; | ||
loading: boolean; | ||
error: Error | undefined; | ||
} | ||
|
||
const SubmissionsView: React.FC<SubmissionsViewProps> = ({ | ||
applications, | ||
loading, | ||
error, | ||
}) => { | ||
if (loading) return <DelayedLoadingIndicator msDelayBeforeVisible={500} />; | ||
if (error) return <ErrorFallback error={error} />; | ||
if (applications.length === 0) | ||
return ( | ||
<Typography variant="body1"> | ||
No submitted applications found for this service. | ||
</Typography> | ||
); | ||
return ( | ||
<List> | ||
{applications.map((application, index) => ( | ||
<ListItem key={index}>{application.sessionId}</ListItem> | ||
))} | ||
</List> | ||
); | ||
}; | ||
|
||
export default SubmissionsView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/submissionData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useQuery } from "@apollo/client"; | ||
import gql from "graphql-tag"; | ||
import { useMemo } from "react"; | ||
|
||
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 = { | ||
sessionId: string; | ||
submittedAt: Date | string; | ||
paymentRequests: PaymentRequest[] | null; | ||
paymentStatus: PaymentStatus[] | null; | ||
bopsApplications: BopsApplication[] | null; | ||
uniformApplications: UniformApplication[] | null; | ||
emailApplications: EmailApplication[] | null; | ||
}; | ||
|
||
export type SubmittedApplicationsQueryResult = { | ||
submissionServicesSummary: SubmissionData[]; | ||
}; | ||
|
||
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 } | ||
} | ||
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 | ||
} | ||
} | ||
`; | ||
|
||
type UseSubmittedApplicationsParams = { | ||
flowSlug?: string; | ||
teamSlug?: string; | ||
}; | ||
|
||
export const useSubmittedApplications = ({ | ||
flowSlug, | ||
teamSlug, | ||
}: UseSubmittedApplicationsParams) => { | ||
const { data, loading, error } = useQuery<SubmittedApplicationsQueryResult>( | ||
SUBMITTED_APPLICATIONS_QUERY, | ||
{ | ||
variables: { service_slug: flowSlug, team_slug: teamSlug }, | ||
skip: !flowSlug || !teamSlug, | ||
}, | ||
); | ||
|
||
const applications = useMemo( | ||
() => data?.submissionServicesSummary || [], | ||
[data], | ||
); | ||
|
||
return { applications, loading, error }; | ||
}; |
75 changes: 0 additions & 75 deletions
75
....uk/src/pages/FlowEditor/components/Settings/Submissions/submissionDataTypesAndQueries.ts
This file was deleted.
Oops, something went wrong.