From 91ec0bb45d3bee445753aa2b03c24eabb98c430d Mon Sep 17 00:00:00 2001 From: Kevin Haube Date: Tue, 13 Feb 2024 15:46:07 -0500 Subject: [PATCH] feat(alerts): Modal and Alert banner upgrades (#366) * Undo template: IssueRai * Undo template: RespondToRai * Undo template: WithdrawRai * Undo template: WithdrawPackage * Initialize alert content * Initialize alert content * Remove random modal usage from ActionCard * Remove unused alert banner from Details * Remove unused alert banner from Details * Initialize new modal context * Plug in context provider * Implement CHIP SPA cancel modal; refine interface * Implement Medicaid SPA cancel modal * Undo handleSubmit abstraction: IssueRai * Undo handleSubmit abstraction: RespondToRai * Undo handleSubmit abstraction: WithdrawRai * Undo handleSubmit abstraction: WithdrawPackage * Fix Medicaid SPA routing * Implement IssueRai cancel modal * Implement RespondToRai cancel modal * Implement WithdrawRai cancel modal * Implement WithdrawPackage cancel modal * Implement ToggleRaiWithdraw cancel modal * Remove old modal context * Modify modalContext for custom onAccept * Modify Medicaid SPA cancel modal onAccept * Modify CHIP SPA cancel modal onAccept * Modify IssueRai cancel modal onAccept * Modify RespondToRai cancel modal onAccept * Modify ToggleRaiWithdraw cancel modal onAccept * Modify WithdrawPackage cancel modal onAccept * Modify WithdrawRai cancel modal onAccept * Fix setOnSubmit calls * Implement confirmation modal for WithdrawPackage * Implement confirmation modal for WithdrawRai * Initialize AlertContext * Style success Alert variant * Implement alert context for CHIP SPA * Implement alert context for Medicaid SPA * Add close button to Alert ui * Implement alert context for IssueRai * Implement alert context for RespondToRai * Implement alert context for ToggleRaiWithdraw * Implement alert context for WithdrawRai * Implement alert context for WithdrawPackage * Update alert with route based hiding * Update alert with route based hiding; remaining forms * Update Withdraw confirmation pattern * Undo destructure for contexts: Medicaid SPA * Undo destructure for contexts: CHIP SPA * Undo destructure for contexts: IssueRai * Undo destructure for contexts: RespondToRai * Undo destructure for contexts: ToggleRaiWithdraw * Undo destructure for contexts: WithdrawRai * Undo destructure for contexts: WithdrawPackage * Fix isLoading var source * Update docs with code style * Add alertContext tests * Fix alertContext test * Add modalContext tests * Implement banners and modals on capitated b waivers * Implement banners and modals on contracting b waivers * Fix routing * Add origin query * Origin navigation: CHIP SPA * Origin navigation: Medicaid SPA * Origin navigation: Capitated B waivers * Origin navigation: Contracting B waivers * Origin navigation: Tooling update * Origin navigation: Actions * Docs: formOrigin util * Cleanup: formOrigin --- docs/docs/team-norms/code-style.md | 86 +++++++ .../ui/src/components/Alert/index.tsx | 2 + .../ui/src/components/Cards/OptionCard.tsx | 2 +- .../components/Context/alertContext.test.tsx | 64 ++++++ .../src/components/Context/alertContext.tsx | 74 ++++++ .../components/Context/modalContext.test.tsx | 72 ++++++ .../src/components/Context/modalContext.tsx | 54 +++++ .../ui/src/components/Layout/index.tsx | 62 ++--- .../ui/src/hooks/useActionFormController.ts | 32 --- .../ui/src/pages/actions/IssueRai.tsx | 202 ++++++++++++++--- .../ui/src/pages/actions/RespondToRai.tsx | 196 +++++++++++++--- .../actions/ToggleRaiResponseWithdraw.tsx | 55 ++++- .../ui/src/pages/actions/WithdrawPackage.tsx | 211 +++++++++++++++--- .../ui/src/pages/actions/WithdrawRai.tsx | 199 ++++++++++++++--- src/services/ui/src/pages/actions/index.tsx | 11 +- .../ui/src/pages/actions/template.tsx | 126 ----------- .../dashboard/Lists/renderCells/index.tsx | 2 +- src/services/ui/src/pages/detail/index.tsx | 82 +------ src/services/ui/src/pages/form/chip-form.tsx | 52 ++++- .../ui/src/pages/form/medicaid-form.tsx | 60 +++-- src/services/ui/src/pages/form/modals.tsx | 127 ----------- .../capitated-1915-b-waiver-amendment.tsx | 52 ++++- .../capitated-1915-b-waiver-initial.tsx | 51 ++++- .../capitated-1915-b-waiver-renewal.tsx | 51 ++++- .../contracting-1915-b-waiver-amendment.tsx | 51 ++++- .../contracting-1915-b-waiver-initial.tsx | 51 ++++- .../contracting-1915-b-waiver-renewal.tsx | 51 ++++- src/services/ui/src/utils/formOrigin.ts | 29 +++ 28 files changed, 1478 insertions(+), 629 deletions(-) create mode 100644 docs/docs/team-norms/code-style.md create mode 100644 src/services/ui/src/components/Context/alertContext.test.tsx create mode 100644 src/services/ui/src/components/Context/alertContext.tsx create mode 100644 src/services/ui/src/components/Context/modalContext.test.tsx create mode 100644 src/services/ui/src/components/Context/modalContext.tsx delete mode 100644 src/services/ui/src/hooks/useActionFormController.ts delete mode 100644 src/services/ui/src/pages/actions/template.tsx delete mode 100644 src/services/ui/src/pages/form/modals.tsx create mode 100644 src/services/ui/src/utils/formOrigin.ts diff --git a/docs/docs/team-norms/code-style.md b/docs/docs/team-norms/code-style.md new file mode 100644 index 0000000000..fca3a870c4 --- /dev/null +++ b/docs/docs/team-norms/code-style.md @@ -0,0 +1,86 @@ +--- +layout: default +title: Code Style Cheatsheet +parent: Team Norms +nav_order: 2 +--- + +# Code Style + +### What is it? + +A set of rules or guidelines used when writing the source code for a computer program. + +### Why is it? + +It keeps the code looking neat and tidy, so anyone on the team can jump in and not +get lost in a jungle of curly braces and indentation levels. It's like everyone speaking +the same slang in a super cool secret club. Plus, it saves time from arguing over trivial +stuff, like whether tabs are better than spaces, so there's more time for the fun +stuff—coding and creating! + +# OneMAC Style Norms + +## Cheatsheet + +TL;DR? No worries, here's a cheatsheet of the concepts outlined below: + +- [DO NOT destructure](#object-access) so we maintain object context for methods and properties used in code + +### Object Access + +When integrating with complex objects, consider maintaining the object's integrity rather +than opting for destructuring. This approach ensures that the object's context is +preserved, enhancing readability and maintainability. + +#### Nomenclature simplification + +For instance, rather than breaking +down the object into individual variables, which can lead to verbose and confusing naming +conventions, maintain the object as a whole. + +```typescript jsx +const { + setModalOpen, + setContent: setModalContent, + setOnAccept: setModalOnAccept, +} = useModalContext(); +const { + setContent: setBannerContent, + setBannerShow, + setBannerDisplayOn, +} = useAlertContext(); + +// vs + +const modal = useModalContext(); +const alert = useAlertContext(); +``` + +#### Usage implication + +This method simplifies reference to its properties and methods, providing a clearer and +more direct understanding of its usage within the code. This strategy is particularly +beneficial in scenarios where the object's structure and context significantly contribute +to its functionality and meaning in the application. + +```typescript jsx +
{ + try { + await submit({ + //... + }); + alert.setContent({ + header: "RAI response submitted", + body: `The RAI response for ${item._source.id} has been submitted.`, + }); + alert.setBannerShow(true); + alert.setBannerDisplayOn("/dashboard"); + navigate({ path: "/dashboard" }); + } catch (e) { + //... + } + })} +> +``` \ No newline at end of file diff --git a/src/services/ui/src/components/Alert/index.tsx b/src/services/ui/src/components/Alert/index.tsx index bd1d5f972a..5478f0700e 100644 --- a/src/services/ui/src/components/Alert/index.tsx +++ b/src/services/ui/src/components/Alert/index.tsx @@ -13,6 +13,8 @@ const alertVariants = cva( "border-destructive/50 text-destructive [&>svg]:text-destructive", infoBlock: "border-l-[6px] border-y-0 border-r-0 border-cyan-500 bg-cyan-300/10 rounded-none", + success: + "border-l-[6px] border-[#2E8540] border-y-0 border-r-0 bg-[#E7F4E4]", }, }, defaultVariants: { diff --git a/src/services/ui/src/components/Cards/OptionCard.tsx b/src/services/ui/src/components/Cards/OptionCard.tsx index 60d098a50f..881a44cb63 100644 --- a/src/services/ui/src/components/Cards/OptionCard.tsx +++ b/src/services/ui/src/components/Cards/OptionCard.tsx @@ -37,7 +37,7 @@ export const OptionCard = ({ }: MACFieldsetOption) => { return (