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

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,6 +11,7 @@ export type BuyDownCalculatorInputs = {
11
11
  purchasePrice: number;
12
12
  downpayment: number;
13
13
  dealerContribution: number;
14
+ manufacturerContributionAmount: number;
14
15
  program: string;
15
16
  fico: string;
16
17
  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 } from "react";
6
+ import { useState, useEffect } 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,7 +39,6 @@ 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("");
43
42
  const [nonBuydownPayment, setNonBuydownPayment] = useState("");
44
43
  const [totalBuydownCost, setTotalBuydownCost] = useState("");
45
44
  const [monthlySavings, setMonthlySavings] = useState("");
@@ -47,6 +46,11 @@ const BuyDownCalculator = ({
47
46
  const [enableFullTimeCharter, setEnableFullTimeCharter] = useState(false);
48
47
  const [disableMooringOutside, setDisableMooringOutside] = useState(false);
49
48
  const [disableLTVAbove60, setDisableLTVAbove60] = useState(true);
49
+ const [isDealerContributionDisabled, setIsDealerContributionDisabled] = useState(false);
50
+ const [
51
+ isManufacturerContributionDisabled,
52
+ setIsManufacturerContributionDisabled
53
+ ] = useState(false);
50
54
  const schema = z.object({
51
55
  purchasePrice: z.string().min(1, { message: "Loan amount is required." }).transform((val) => {
52
56
  return formatToNumber(val);
@@ -54,8 +58,13 @@ const BuyDownCalculator = ({
54
58
  downpayment: z.string().min(1, { message: "Down Payment is required." }).transform((val) => {
55
59
  return formatToNumber(val);
56
60
  }),
57
- dealerContribution: z.string().min(1, { message: "Dealer Contribution is required." }).transform((val) => {
58
- return formatToNumber(val);
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;
59
68
  }),
60
69
  program: z.string().min(1, { message: "Program is required." }),
61
70
  fico: z.string().min(1, { message: "FICO is required." }),
@@ -66,7 +75,32 @@ const BuyDownCalculator = ({
66
75
  return formatToNumber(val);
67
76
  })
68
77
  }).superRefine((values, ctx) => {
69
- const { purchasePrice, downpayment, program, buydownTerm } = values;
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
+ }
70
104
  if (program === "3/6 SOFR ARM" && (buydownTerm === 4 || buydownTerm === 5)) {
71
105
  ctx.addIssue({
72
106
  code: z.ZodIssueCode.custom,
@@ -114,8 +148,23 @@ const BuyDownCalculator = ({
114
148
  handleSubmit,
115
149
  register,
116
150
  setValue,
151
+ watch,
152
+ trigger,
117
153
  formState: { errors, isValid }
118
154
  } = 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]);
119
168
  const calculator_variant = getVariant(variant);
120
169
  const enableDependentInputs = enableFullTimeCharter;
121
170
  const formatToNumber = (value) => {
@@ -224,6 +273,32 @@ const BuyDownCalculator = ({
224
273
  setDisableMooringOutside(true);
225
274
  }
226
275
  };
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
+ };
227
302
  const updateFicoRequirements = (loanRangeValue, program) => {
228
303
  const ficoOptionsToDisable = ["700-719", "720-759"];
229
304
  const ficoSelect = document.getElementById("fico");
@@ -383,17 +458,17 @@ const BuyDownCalculator = ({
383
458
  setTotalBuydownCost(formatToCurrency(TBC));
384
459
  return TBC;
385
460
  };
386
- const calculateManufacturerContribution = (dealerContribution) => {
387
- const manufacturerContribution = 100 - dealerContribution;
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
+ }
388
468
  const percentage = formatToPercentage(manufacturerContribution);
389
469
  setManuContributionPercentage(percentage);
390
470
  return manufacturerContribution;
391
471
  };
392
- const calculateManufacturerAmount = (totalBuydownCost2, manufacturerContribution) => {
393
- const manufacturerAmount = totalBuydownCost2 * (manufacturerContribution / 100);
394
- const formattedAmount = formatToCurrency(manufacturerAmount);
395
- setManuContributionAmount(formattedAmount);
396
- };
397
472
  const calculateDealerContributionAmount = (dealerContribution, totalBuydownCost2) => {
398
473
  const dealerContributionValue = totalBuydownCost2 * (dealerContribution / 100);
399
474
  const formattedAmount = formatToCurrency(dealerContributionValue);
@@ -405,6 +480,7 @@ const BuyDownCalculator = ({
405
480
  buydownRate,
406
481
  buydownTerm,
407
482
  dealerContribution,
483
+ manufacturerContributionAmount,
408
484
  downpayment,
409
485
  fico,
410
486
  program,
@@ -436,8 +512,11 @@ const BuyDownCalculator = ({
436
512
  financedAmountValue,
437
513
  buydownTerm
438
514
  );
439
- const manufacturerContribution = calculateManufacturerContribution(dealerContribution);
440
- calculateManufacturerAmount(totalBuydownCost2, manufacturerContribution);
515
+ calculateManufacturerContribution(
516
+ dealerContribution,
517
+ manufacturerContributionAmount,
518
+ totalBuydownCost2
519
+ );
441
520
  calculateDealerContributionAmount(dealerContribution, totalBuydownCost2);
442
521
  }
443
522
  };
@@ -495,16 +574,40 @@ const BuyDownCalculator = ({
495
574
  PercentageInput,
496
575
  {
497
576
  id: "dealerContribution",
498
- ...register("dealerContribution", { required: true }),
577
+ ...register("dealerContribution", {
578
+ required: false,
579
+ onChange: handleDealerContributionChange
580
+ }),
499
581
  sizes: "medium",
500
582
  placeholder: "0.00%",
501
583
  label: "Dealer Contribution",
502
- required: true,
584
+ required: false,
503
585
  error: !!errors["dealerContribution"],
504
586
  helperText: errors["dealerContribution"]?.message,
505
- variant: calculator_variant
587
+ variant: calculator_variant,
588
+ disabled: isDealerContributionDisabled
506
589
  }
507
590
  ) }),
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: [
508
611
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
509
612
  Dropdown,
510
613
  {
@@ -526,9 +629,7 @@ const BuyDownCalculator = ({
526
629
  Program.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
527
630
  ]
528
631
  }
529
- ) })
530
- ] }),
531
- /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
632
+ ) }),
532
633
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
533
634
  Dropdown,
534
635
  {
@@ -546,7 +647,9 @@ const BuyDownCalculator = ({
546
647
  Fico.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
547
648
  ]
548
649
  }
549
- ) }),
650
+ ) })
651
+ ] }),
652
+ /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
550
653
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
551
654
  Input,
552
655
  {
@@ -558,10 +661,8 @@ const BuyDownCalculator = ({
558
661
  variant: calculator_variant,
559
662
  value: loanRange
560
663
  }
561
- ) })
562
- ] }),
563
- /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
564
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
664
+ ) }),
665
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
565
666
  Dropdown,
566
667
  {
567
668
  id: "buydownRate",
@@ -574,35 +675,31 @@ const BuyDownCalculator = ({
574
675
  error: !!errors.buydownRate,
575
676
  helperText: errors.buydownRate?.message,
576
677
  variant: calculator_variant,
577
- defaultValue: "",
578
- children: [
579
- /* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select Buydown Rate" }),
580
- BuydownRate.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
581
- ]
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
- ]
678
+ disabled: true,
679
+ defaultValue: 3.74,
680
+ children: BuydownRate.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
603
681
  }
604
682
  ) })
605
683
  ] }),
684
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
685
+ Dropdown,
686
+ {
687
+ id: "buydownTerm",
688
+ ...register("buydownTerm", {
689
+ required: true,
690
+ deps: ["program"]
691
+ }),
692
+ label: "Buydown Term (1-5 Years)",
693
+ sizes: "medium",
694
+ required: true,
695
+ error: !!errors.buydownTerm,
696
+ helperText: errors.buydownTerm?.message,
697
+ variant: calculator_variant,
698
+ disabled: true,
699
+ defaultValue: 3,
700
+ children: BuydownTerm.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.text }, item.value))
701
+ }
702
+ ) }) }),
606
703
  /* @__PURE__ */ jsx("div", { className: `${row_form}`, children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("label", { children: "Loan Level Rate Adjustments" }) }) }),
607
704
  /* @__PURE__ */ jsxs("div", { className: `${row_form}`, children: [
608
705
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", { className: row_form, children: /* @__PURE__ */ jsxs(
@@ -788,23 +885,23 @@ const BuyDownCalculator = ({
788
885
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
789
886
  CurrencyInput,
790
887
  {
791
- id: "manuContributionAmount",
888
+ id: "nonBuydownPayment",
792
889
  sizes: "medium",
793
- label: "Manufacturer Contribution Amount",
890
+ label: "Non-buydown Payment",
794
891
  disabled: true,
795
892
  variant: calculator_variant,
796
- value: manuContributionAmount
893
+ value: nonBuydownPayment
797
894
  }
798
895
  ) }),
799
896
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
800
897
  CurrencyInput,
801
898
  {
802
- id: "nonBuydownPayment",
899
+ id: "totalBuydownCost",
803
900
  sizes: "medium",
804
- label: "Non-buydown Payment",
901
+ label: "Total Buydown Cost",
805
902
  disabled: true,
806
903
  variant: calculator_variant,
807
- value: nonBuydownPayment
904
+ value: totalBuydownCost
808
905
  }
809
906
  ) })
810
907
  ] }),
@@ -812,38 +909,27 @@ const BuyDownCalculator = ({
812
909
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
813
910
  CurrencyInput,
814
911
  {
815
- id: "totalBuydownCost",
912
+ id: "monthlySavings",
816
913
  sizes: "medium",
817
- label: "Total Buydown Cost",
914
+ label: "Monthly Savings",
818
915
  disabled: true,
819
916
  variant: calculator_variant,
820
- value: totalBuydownCost
917
+ value: monthlySavings
821
918
  }
822
919
  ) }),
823
920
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
824
921
  CurrencyInput,
825
922
  {
826
- id: "monthlySavings",
923
+ id: "dealerContributionAmount",
827
924
  sizes: "medium",
828
- label: "Monthly Savings",
925
+ label: "Dealer Contribution Amount",
829
926
  disabled: true,
830
927
  variant: calculator_variant,
831
- value: monthlySavings
928
+ value: dealerContributionAmount,
929
+ helperText: "Dealer reserve offset not included in this amount."
832
930
  }
833
931
  ) })
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
- ) }) })
932
+ ] })
847
933
  ]
848
934
  }
849
935
  ) }),
@@ -8,10 +8,6 @@ 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, contextData, }: FormProps & {
11
+ export declare const ContactUsLVF: ({ icon, children, onSubmit, disclosure, variant: fullVariant, headline, description, callToAction, validateEmail, onValidate, id, dealerCheckbox, }: FormProps & {
12
12
  dealerCheckbox?: boolean;
13
- contextData?: {
14
- pageName?: string;
15
- pageUri?: string;
16
- };
17
13
  }) => import("react/jsx-runtime").JSX.Element;
@@ -47,8 +47,7 @@ const ContactUsLVF = ({
47
47
  validateEmail,
48
48
  onValidate,
49
49
  id,
50
- dealerCheckbox = true,
51
- contextData
50
+ dealerCheckbox = true
52
51
  }) => {
53
52
  const schema = z.object({
54
53
  firstname: z.string().regex(/^[a-zA-Z]*(?:[a-zA-Z][a-zA-Z'-]*\s{0,1}){2,}$/g, {
@@ -107,9 +106,9 @@ const ContactUsLVF = ({
107
106
  return { name: key, value: data[key] };
108
107
  }
109
108
  }).filter((el) => el !== void 0);
110
- const finalContextData = {
111
- pageName: contextData?.pageName || "La Victoire Finance",
112
- pageUri: contextData?.pageUri || "https://lavictoirefinance.com/contact-us"
109
+ const contextData = {
110
+ pageName: "La Victoire Finance",
111
+ pageUri: "https://lavictoirefinance.com/contact-us"
113
112
  };
114
113
  const legalConsentData = {
115
114
  consent: {
@@ -126,7 +125,7 @@ const ContactUsLVF = ({
126
125
  };
127
126
  await onSubmit({
128
127
  fields: formattedFieldsData,
129
- context: finalContextData,
128
+ context: contextData,
130
129
  legalConsentOptions: legalConsentData,
131
130
  form: "contactUSLVF"
132
131
  });
@@ -177,20 +177,8 @@ const Fico = [
177
177
  { value: "720-759", text: "720-759" },
178
178
  { value: "700-719", text: "700-719" }
179
179
  ];
180
- const BuydownRate = [
181
- { value: 2.99, text: "2.99%" },
182
- { value: 3.99, text: "3.99%" },
183
- { value: 4.99, text: "4.99%" },
184
- { value: 5.99, text: "5.99%" },
185
- { value: 6.99, text: "6.99%" }
186
- ];
187
- const BuydownTerm = [
188
- { value: 1, text: "1 Year" },
189
- { value: 2, text: "2 Years" },
190
- { value: 3, text: "3 Years" },
191
- { value: 4, text: "4 Years" },
192
- { value: 5, text: "5 Years" }
193
- ];
180
+ const BuydownRate = [{ value: 3.74, text: "3.74%" }];
181
+ const BuydownTerm = [{ value: 3, text: "3 Years" }];
194
182
  const LoanRates = /* @__PURE__ */ new Map([
195
183
  [
196
184
  "3/6 SOFR ARM",
@@ -32,6 +32,7 @@ const Dropdown = forwardRef(
32
32
  "select",
33
33
  {
34
34
  ...rest,
35
+ disabled,
35
36
  className: clsx(
36
37
  props.className,
37
38
  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-lvfformcontextdata",
4
+ "version": "1.0.100-feature-buydown.2",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",