Skip to content

Commit

Permalink
feat: Import fee breakdown logic from planx-core
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 5, 2024
1 parent 6ed8a32 commit 08d7440
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 462 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { getFeeBreakdown } from "@opensystemslab/planx-core";
import { FeeBreakdown } from "@opensystemslab/planx-core/types";
import { logger } from "airbrake";
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
Expand All @@ -16,17 +15,15 @@ export const useFeeBreakdown = (): FeeBreakdown | undefined => {
state.computePassport().data,
state.sessionId,
]);
if (!passportData) return

const schema = createPassportSchema();
const result = schema.safeParse(passportData);
if (!passportData) return;

if (!result.success) {
try {
const feeBreakdown = getFeeBreakdown(passportData);
return feeBreakdown;
} catch (error) {
logger.notify(
`Failed to parse fee breakdown data from passport for session ${sessionId}. Error: ${result.error}`,
`Failed to parse fee breakdown data from passport for session ${sessionId}. Error: ${error}`,
);
return;
}

return result.data;
};
Loading

0 comments on commit 08d7440

Please sign in to comment.