Skip to content

Commit

Permalink
docs: Add some JSDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 5, 2024
1 parent 1cf094b commit 4f2344c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 4f2344c

Please sign in to comment.