From 4f2344c333d30b3b49b426653cca2183b5869142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 27 Nov 2024 12:11:42 +0000 Subject: [PATCH] docs: Add some JSDocs --- .../Pay/Public/FeeBreakdown/useFeeBreakdown.tsx | 8 +++++++- .../@planx/components/Pay/Public/FeeBreakdown/utils.ts | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/useFeeBreakdown.tsx b/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/useFeeBreakdown.tsx index e100052ba2..216ce36f53 100644 --- a/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/useFeeBreakdown.tsx +++ b/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/useFeeBreakdown.tsx @@ -4,6 +4,13 @@ import { useStore } from "pages/FlowEditor/lib/store"; import { FeeBreakdown } from "./types"; import { createPassportSchema } from "./utils"; +/** + * Parses the users's Passport for data variables associated with their fee + * Currently relies on static `application.fee.x` variables + * + * If fee variables not found, or not successfully parsed, we do not show the user a fee breakdown + * Instead an internal error will be raised allowing us to correct the flow content + */ export const useFeeBreakdown = (): FeeBreakdown | undefined => { const [passportData, sessionId] = useStore((state) => [ state.computePassport().data, @@ -12,7 +19,6 @@ export const useFeeBreakdown = (): FeeBreakdown | undefined => { const schema = createPassportSchema(); const result = schema.safeParse(passportData); - // Unable to parse fee data from passport, do not show FeeBreakdown component if (!result.success) { logger.notify( `Failed to parse fee breakdown data from passport for session ${sessionId}. Error: ${result.error}`, diff --git a/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/utils.ts b/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/utils.ts index cd8b41c859..cc27682e3d 100644 --- a/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/utils.ts +++ b/editor.planx.uk/src/@planx/components/Pay/Public/FeeBreakdown/utils.ts @@ -5,11 +5,18 @@ import { FeeBreakdown, PassportFeeFields } from "./types"; export const toNumber = (input: number | [number]) => Array.isArray(input) ? input[0] : input; +/** + * A "reduction" is the sum of the difference between calculated and payable + * This is not currently broken down further into component parts, or as exemptions or reductions + */ export const calculateReduction = (data: PassportFeeFields) => data["application.fee.calculated"] ? data["application.fee.calculated"] - data["application.fee.payable"] : 0; +/** + * Transform Passport data to a FeeBreakdown shape + */ export const toFeeBreakdown = (data: PassportFeeFields): FeeBreakdown => ({ applicationFee: data["application.fee.calculated"] || data["application.fee.payable"],