@axos-web-dev/shared-components 1.0.100-feature-buydown.1 → 1.0.100-feature-lvfformcontextdata

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,6 @@ export type BuyDownCalculatorInputs = {
11
11
  purchasePrice: number;
12
12
  downpayment: number;
13
13
  dealerContribution: number;
14
- manufacturerContributionAmount: number;
15
14
  program: string;
16
15
  fico: string;
17
16
  buydownRate: number;
@@ -3,7 +3,7 @@ import { jsxs, jsx } from "react/jsx-runtime";
3
3
  import { zodResolver } from "@hookform/resolvers/zod";
4
4
  import { Button } from "../../Button/Button.js";
5
5
  import "../../Button/Button.css.js";
6
- import { useState, useEffect } from "react";
6
+ import { useState } from "react";
7
7
  import "react-use";
8
8
  import { Program, Fico, BuydownRate, BuydownTerm, LoanRates } from "../../Forms/FormEnums.js";
9
9
  import { Checkbox } from "../../Input/Checkbox.js";
@@ -39,6 +39,7 @@ const BuyDownCalculator = ({
39
39
  const [finalNoteRate, setFinalNoteRate] = useState("");
40
40
  const [manuContributionPercentage, setManuContributionPercentage] = useState("");
41
41
  const [buydownPayment, setBuydownPayment] = useState("");
42
+ const [manuContributionAmount, setManuContributionAmount] = useState("");
42
43
  const [nonBuydownPayment, setNonBuydownPayment] = useState("");
43
44
  const [totalBuydownCost, setTotalBuydownCost] = useState("");
44
45
  const [monthlySavings, setMonthlySavings] = useState("");
@@ -46,11 +47,6 @@ const BuyDownCalculator = ({
46
47
  const [enableFullTimeCharter, setEnableFullTimeCharter] = useState(false);
47
48
  const [disableMooringOutside, setDisableMooringOutside] = useState(false);
48
49
  const [disableLTVAbove60, setDisableLTVAbove60] = useState(true);
49
- const [isDealerContributionDisabled, setIsDealerContributionDisabled] = useState(false);
50
- const [
51
- isManufacturerContributionDisabled,
52
- setIsManufacturerContributionDisabled
53
- ] = useState(false);
54
50
  const schema = z.object({
55
51
  purchasePrice: z.string().min(1, { message: "Loan amount is required." }).transform((val) => {
56
52
  return formatToNumber(val);
@@ -58,13 +54,8 @@ const BuyDownCalculator = ({
58
54
  downpayment: z.string().min(1, { message: "Down Payment is required." }).transform((val) => {
59
55
  return formatToNumber(val);
60
56
  }),
61
- dealerContribution: z.union([z.string(), z.number()]).optional().transform((val) => {
62
- if (typeof val === "number") return val;
63
- return val ? formatToNumber(val) : 0;
64
- }),
65
- manufacturerContributionAmount: z.union([z.string(), z.number()]).optional().transform((val) => {
66
- if (typeof val === "number") return val;
67
- return val ? formatToNumber(val) : 0;
57
+ dealerContribution: z.string().min(1, { message: "Dealer Contribution is required." }).transform((val) => {
58
+ return formatToNumber(val);
68
59
  }),
69
60
  program: z.string().min(1, { message: "Program is required." }),
70
61
  fico: z.string().min(1, { message: "FICO is required." }),
@@ -75,32 +66,7 @@ const BuyDownCalculator = ({
75
66
  return formatToNumber(val);
76
67
  })
77
68
  }).superRefine((values, ctx) => {
78
- const {
79
- purchasePrice,
80
- downpayment,
81
- program,
82
- buydownTerm,
83
- dealerContribution,
84
- manufacturerContributionAmount
85
- } = values;
86
- if (dealerContribution > 0 && manufacturerContributionAmount > 0) {
87
- ctx.addIssue({
88
- code: z.ZodIssueCode.custom,
89
- path: ["dealerContribution"],
90
- message: "Cannot specify both Dealer Contribution and Manufacturer Contribution Amount. Please choose one."
91
- });
92
- ctx.addIssue({
93
- code: z.ZodIssueCode.custom,
94
- path: ["manufacturerContributionAmount"],
95
- message: "Cannot specify both Dealer Contribution and Manufacturer Contribution Amount. Please choose one."
96
- });
97
- } else if (dealerContribution === 0 && manufacturerContributionAmount === 0) {
98
- ctx.addIssue({
99
- code: z.ZodIssueCode.custom,
100
- path: ["dealerContribution"],
101
- message: "Either Dealer Contribution or Manufacturer Contribution Amount is required."
102
- });
103
- }
69
+ const { purchasePrice, downpayment, program, buydownTerm } = values;
104
70
  if (program === "3/6 SOFR ARM" && (buydownTerm === 4 || buydownTerm === 5)) {
105
71
  ctx.addIssue({
106
72
  code: z.ZodIssueCode.custom,
@@ -148,23 +114,8 @@ const BuyDownCalculator = ({
148
114
  handleSubmit,
149
115
  register,
150
116
  setValue,
151
- watch,
152
- trigger,
153
117
  formState: { errors, isValid }
154
118
  } = methods;
155
- const watchedFields = watch(["purchasePrice", "downpayment", "program"]);
156
- useEffect(() => {
157
- const [purchasePrice, downpayment, program] = watchedFields;
158
- if (purchasePrice && downpayment && program) {
159
- const purchasePriceNum = typeof purchasePrice === "string" ? formatToNumber(purchasePrice) : purchasePrice;
160
- const downpaymentNum = typeof downpayment === "string" ? formatToNumber(downpayment) : downpayment;
161
- if (purchasePriceNum > 0 && downpaymentNum >= 0 && purchasePriceNum > downpaymentNum) {
162
- const financedAmount2 = purchasePriceNum - downpaymentNum;
163
- const loanRange2 = getRange(financedAmount2, program);
164
- setLoanRange(loanRange2);
165
- }
166
- }
167
- }, [watchedFields]);
168
119
  const calculator_variant = getVariant(variant);
169
120
  const enableDependentInputs = enableFullTimeCharter;
170
121
  const formatToNumber = (value) => {
@@ -273,32 +224,6 @@ const BuyDownCalculator = ({
273
224
  setDisableMooringOutside(true);
274
225
  }
275
226
  };
276
- const handleDealerContributionChange = (event) => {
277
- const value = event.target.value;
278
- const numericValue = formatToNumber(value);
279
- if (numericValue > 0) {
280
- setIsManufacturerContributionDisabled(true);
281
- setValue("manufacturerContributionAmount", 0);
282
- } else {
283
- setIsManufacturerContributionDisabled(false);
284
- }
285
- setTimeout(() => {
286
- trigger();
287
- }, 0);
288
- };
289
- const handleManufacturerContributionChange = (event) => {
290
- const value = event.target.value;
291
- const numericValue = formatToNumber(value);
292
- if (numericValue > 0) {
293
- setIsDealerContributionDisabled(true);
294
- setValue("dealerContribution", 0);
295
- } else {
296
- setIsDealerContributionDisabled(false);
297
- }
298
- setTimeout(() => {
299
- trigger();
300
- }, 0);
301
- };
302
227
  const updateFicoRequirements = (loanRangeValue, program) => {
303
228
  const ficoOptionsToDisable = ["700-719", "720-759"];
304
229
  const ficoSelect = document.getElementById("fico");
@@ -458,17 +383,17 @@ const BuyDownCalculator = ({
458
383
  setTotalBuydownCost(formatToCurrency(TBC));
459
384
  return TBC;
460
385
  };
461
- const calculateManufacturerContribution = (dealerContribution, manufacturerContributionAmount, totalBuydownCost2) => {
462
- let manufacturerContribution;
463
- if (manufacturerContributionAmount > 0) {
464
- manufacturerContribution = manufacturerContributionAmount / totalBuydownCost2 * 100;
465
- } else {
466
- manufacturerContribution = 100 - dealerContribution;
467
- }
386
+ const calculateManufacturerContribution = (dealerContribution) => {
387
+ const manufacturerContribution = 100 - dealerContribution;
468
388
  const percentage = formatToPercentage(manufacturerContribution);
469
389
  setManuContributionPercentage(percentage);
470
390
  return manufacturerContribution;
471
391
  };
392
+ const calculateManufacturerAmount = (totalBuydownCost2, manufacturerContribution) => {
393
+ const manufacturerAmount = totalBuydownCost2 * (manufacturerContribution / 100);
394
+ const formattedAmount = formatToCurrency(manufacturerAmount);
395
+ setManuContributionAmount(formattedAmount);
396
+ };
472
397
  const calculateDealerContributionAmount = (dealerContribution, totalBuydownCost2) => {
473
398
  const dealerContributionValue = totalBuydownCost2 * (dealerContribution / 100);
474
399
  const formattedAmount = formatToCurrency(dealerContributionValue);
@@ -480,7 +405,6 @@ const BuyDownCalculator = ({
480
405
  buydownRate,
481
406
  buydownTerm,
482
407
  dealerContribution,
483
- manufacturerContributionAmount,
484
408
  downpayment,
485
409
  fico,
486
410
  program,
@@ -512,11 +436,8 @@ const BuyDownCalculator = ({
512
436
  financedAmountValue,
513
437
  buydownTerm
514
438
  );
515
- calculateManufacturerContribution(
516
- dealerContribution,
517
- manufacturerContributionAmount,
518
- totalBuydownCost2
519
- );
439
+ const manufacturerContribution = calculateManufacturerContribution(dealerContribution);
440
+ calculateManufacturerAmount(totalBuydownCost2, manufacturerContribution);
520
441
  calculateDealerContributionAmount(dealerContribution, totalBuydownCost2);
521
442
  }
522
443
  };
@@ -574,40 +495,16 @@ const BuyDownCalculator = ({
574
495
  PercentageInput,
575
496
  {
576
497
  id: "dealerContribution",
577
- ...register("dealerContribution", {
578
- required: false,
579
- onChange: handleDealerContributionChange
580
- }),
498
+ ...register("dealerContribution", { required: true }),
581
499
  sizes: "medium",
582
500
  placeholder: "0.00%",
583
501
  label: "Dealer Contribution",
584
- required: false,
502
+ required: true,
585
503
  error: !!errors["dealerContribution"],
586
504
  helperText: errors["dealerContribution"]?.message,
587
- variant: calculator_variant,
588
- disabled: isDealerContributionDisabled
505
+ variant: calculator_variant
589
506
  }
590
507
  ) }),
591
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
592
- CurrencyInput,
593
- {
594
- id: "manufacturerContributionAmount",
595
- ...register("manufacturerContributionAmount", {
596
- required: false,
597
- onChange: handleManufacturerContributionChange
598
- }),
599
- sizes: "medium",
600
- placeholder: "$0.00",
601
- label: "Manufacturer Contribution Amount",
602
- required: false,
603
- error: !!errors["manufacturerContributionAmount"],
604
- helperText: errors["manufacturerContributionAmount"]?.message,
605
- variant: calculator_variant,
606
- disabled: isManufacturerContributionDisabled
607
- }
608
- ) })
609
- ] }),
610
- /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
611
508
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
612
509
  Dropdown,
613
510
  {
@@ -629,7 +526,9 @@ const BuyDownCalculator = ({
629
526
  Program.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
630
527
  ]
631
528
  }
632
- ) }),
529
+ ) })
530
+ ] }),
531
+ /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
633
532
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
634
533
  Dropdown,
635
534
  {
@@ -647,9 +546,7 @@ const BuyDownCalculator = ({
647
546
  Fico.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
648
547
  ]
649
548
  }
650
- ) })
651
- ] }),
652
- /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
549
+ ) }),
653
550
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
654
551
  Input,
655
552
  {
@@ -661,7 +558,9 @@ const BuyDownCalculator = ({
661
558
  variant: calculator_variant,
662
559
  value: loanRange
663
560
  }
664
- ) }),
561
+ ) })
562
+ ] }),
563
+ /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
665
564
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
666
565
  Dropdown,
667
566
  {
@@ -681,29 +580,29 @@ const BuyDownCalculator = ({
681
580
  BuydownRate.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
682
581
  ]
683
582
  }
583
+ ) }),
584
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
585
+ Dropdown,
586
+ {
587
+ id: "buydownTerm",
588
+ ...register("buydownTerm", {
589
+ required: true,
590
+ deps: ["program"]
591
+ }),
592
+ label: "Buydown Term (1-5 Years)",
593
+ sizes: "medium",
594
+ required: true,
595
+ error: !!errors.buydownTerm,
596
+ helperText: errors.buydownTerm?.message,
597
+ variant: calculator_variant,
598
+ defaultValue: 0,
599
+ children: [
600
+ /* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select Buydown Term" }),
601
+ BuydownTerm.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
602
+ ]
603
+ }
684
604
  ) })
685
605
  ] }),
686
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
687
- Dropdown,
688
- {
689
- id: "buydownTerm",
690
- ...register("buydownTerm", {
691
- required: true,
692
- deps: ["program"]
693
- }),
694
- label: "Buydown Term (1-5 Years)",
695
- sizes: "medium",
696
- required: true,
697
- error: !!errors.buydownTerm,
698
- helperText: errors.buydownTerm?.message,
699
- variant: calculator_variant,
700
- defaultValue: 0,
701
- children: [
702
- /* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select Buydown Term" }),
703
- BuydownTerm.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
704
- ]
705
- }
706
- ) }) }),
707
606
  /* @__PURE__ */ jsx("div", { className: `${row_form}`, children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("label", { children: "Loan Level Rate Adjustments" }) }) }),
708
607
  /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
709
608
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", { className: row_form, children: /* @__PURE__ */ jsxs(
@@ -889,23 +788,23 @@ const BuyDownCalculator = ({
889
788
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
890
789
  CurrencyInput,
891
790
  {
892
- id: "nonBuydownPayment",
791
+ id: "manuContributionAmount",
893
792
  sizes: "medium",
894
- label: "Non-buydown Payment",
793
+ label: "Manufacturer Contribution Amount",
895
794
  disabled: true,
896
795
  variant: calculator_variant,
897
- value: nonBuydownPayment
796
+ value: manuContributionAmount
898
797
  }
899
798
  ) }),
900
799
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
901
800
  CurrencyInput,
902
801
  {
903
- id: "totalBuydownCost",
802
+ id: "nonBuydownPayment",
904
803
  sizes: "medium",
905
- label: "Total Buydown Cost",
804
+ label: "Non-buydown Payment",
906
805
  disabled: true,
907
806
  variant: calculator_variant,
908
- value: totalBuydownCost
807
+ value: nonBuydownPayment
909
808
  }
910
809
  ) })
911
810
  ] }),
@@ -913,27 +812,38 @@ const BuyDownCalculator = ({
913
812
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
914
813
  CurrencyInput,
915
814
  {
916
- id: "monthlySavings",
815
+ id: "totalBuydownCost",
917
816
  sizes: "medium",
918
- label: "Monthly Savings",
817
+ label: "Total Buydown Cost",
919
818
  disabled: true,
920
819
  variant: calculator_variant,
921
- value: monthlySavings
820
+ value: totalBuydownCost
922
821
  }
923
822
  ) }),
924
823
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
925
824
  CurrencyInput,
926
825
  {
927
- id: "dealerContributionAmount",
826
+ id: "monthlySavings",
928
827
  sizes: "medium",
929
- label: "Dealer Contribution Amount",
828
+ label: "Monthly Savings",
930
829
  disabled: true,
931
830
  variant: calculator_variant,
932
- value: dealerContributionAmount,
933
- helperText: "Dealer reserve offset not included in this amount."
831
+ value: monthlySavings
934
832
  }
935
833
  ) })
936
- ] })
834
+ ] }),
835
+ /* @__PURE__ */ jsx("div", { className: `${row_form}`, children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
836
+ CurrencyInput,
837
+ {
838
+ id: "dealerContributionAmount",
839
+ sizes: "medium",
840
+ label: "Dealer Contribution Amount",
841
+ disabled: true,
842
+ variant: calculator_variant,
843
+ value: dealerContributionAmount,
844
+ helperText: "Dealer reserve offset not included in this amount."
845
+ }
846
+ ) }) })
937
847
  ]
938
848
  }
939
849
  ) }),
@@ -8,6 +8,10 @@ export type ContactUsLaVictoireInputs = {
8
8
  message: string;
9
9
  checkbox: boolean;
10
10
  };
11
- export declare const ContactUsLVF: ({ icon, children, onSubmit, disclosure, variant: fullVariant, headline, description, callToAction, validateEmail, onValidate, id, dealerCheckbox, }: FormProps & {
11
+ export declare const ContactUsLVF: ({ icon, children, onSubmit, disclosure, variant: fullVariant, headline, description, callToAction, validateEmail, onValidate, id, dealerCheckbox, contextData, }: FormProps & {
12
12
  dealerCheckbox?: boolean;
13
+ contextData?: {
14
+ pageName?: string;
15
+ pageUri?: string;
16
+ };
13
17
  }) => import("react/jsx-runtime").JSX.Element;
@@ -47,7 +47,8 @@ const ContactUsLVF = ({
47
47
  validateEmail,
48
48
  onValidate,
49
49
  id,
50
- dealerCheckbox = true
50
+ dealerCheckbox = true,
51
+ contextData
51
52
  }) => {
52
53
  const schema = z.object({
53
54
  firstname: z.string().regex(/^[a-zA-Z]*(?:[a-zA-Z][a-zA-Z'-]*\s{0,1}){2,}$/g, {
@@ -106,9 +107,9 @@ const ContactUsLVF = ({
106
107
  return { name: key, value: data[key] };
107
108
  }
108
109
  }).filter((el) => el !== void 0);
109
- const contextData = {
110
- pageName: "La Victoire Finance",
111
- pageUri: "https://lavictoirefinance.com/contact-us"
110
+ const finalContextData = {
111
+ pageName: contextData?.pageName || "La Victoire Finance",
112
+ pageUri: contextData?.pageUri || "https://lavictoirefinance.com/contact-us"
112
113
  };
113
114
  const legalConsentData = {
114
115
  consent: {
@@ -125,7 +126,7 @@ const ContactUsLVF = ({
125
126
  };
126
127
  await onSubmit({
127
128
  fields: formattedFieldsData,
128
- context: contextData,
129
+ context: finalContextData,
129
130
  legalConsentOptions: legalConsentData,
130
131
  form: "contactUSLVF"
131
132
  });
@@ -32,7 +32,6 @@ const Dropdown = forwardRef(
32
32
  "select",
33
33
  {
34
34
  ...rest,
35
- disabled,
36
35
  className: clsx(
37
36
  props.className,
38
37
  input({ size: sizes }),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axos-web-dev/shared-components",
3
3
  "description": "Axos shared components library for web.",
4
- "version": "1.0.100-feature-buydown.1",
4
+ "version": "1.0.100-feature-lvfformcontextdata",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",