@gusto/embedded-react-sdk 0.10.4 → 0.10.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.5
4
+
5
+ ### Fixes
6
+
7
+ - Corrected an issue where Pay Schedule wasn't clearing errors on cancel navigation
8
+
3
9
  ## 0.10.4
4
10
 
5
11
  ### Fixes
@@ -1,78 +1,80 @@
1
- import { jsx as r, jsxs as u } from "react/jsx-runtime";
2
- import { useState as y, useCallback as A, Suspense as L } from "react";
3
- import { ErrorBoundary as R } from "react-error-boundary";
4
- import { useTranslation as S } from "react-i18next";
5
- import { APIError as E } from "@gusto/embedded-api/models/errors/apierror";
6
- import { SDKValidationError as g } from "@gusto/embedded-api/models/errors/sdkvalidationerror";
7
- import { UnprocessableEntityErrorObject as C } from "@gusto/embedded-api/models/errors/unprocessableentityerrorobject";
8
- import { QueryErrorResetBoundary as B } from "@tanstack/react-query";
9
- import { FadeIn as T } from "../Common/FadeIn/FadeIn.js";
10
- import { BaseContext as _ } from "./useBase.js";
11
- import { componentEvents as j } from "../../shared/constants.js";
1
+ import { jsx as o, jsxs as u } from "react/jsx-runtime";
2
+ import { useState as y, useCallback as E, Suspense as R } from "react";
3
+ import { ErrorBoundary as S } from "react-error-boundary";
4
+ import { useTranslation as B } from "react-i18next";
5
+ import { APIError as g } from "@gusto/embedded-api/models/errors/apierror";
6
+ import { SDKValidationError as C } from "@gusto/embedded-api/models/errors/sdkvalidationerror";
7
+ import { UnprocessableEntityErrorObject as h } from "@gusto/embedded-api/models/errors/unprocessableentityerrorobject";
8
+ import { QueryErrorResetBoundary as T } from "@tanstack/react-query";
9
+ import { FadeIn as _ } from "../Common/FadeIn/FadeIn.js";
10
+ import { BaseContext as j } from "./useBase.js";
11
+ import { componentEvents as F } from "../../shared/constants.js";
12
12
  import { useAsyncError as K } from "../Common/hooks/useAsyncError.js";
13
13
  import "classnames";
14
14
  import { InternalError as P } from "../Common/InternalError/InternalError.js";
15
15
  import { snakeCaseToCamelCase as w } from "../../helpers/formattedStrings.js";
16
- import { useComponentContext as F } from "../../contexts/ComponentAdapter/useComponentContext.js";
17
- import { useLoadingIndicator as M } from "../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
18
- const O = (e) => e.map((o) => o.message ? /* @__PURE__ */ r("li", { children: o.message }, o.key) : null), h = (e, o) => {
19
- const m = o ? o + "." : "";
20
- if (e.category === "invalid_attribute_value" || e.category === "invalid_operation")
16
+ import { useComponentContext as M } from "../../contexts/ComponentAdapter/useComponentContext.js";
17
+ import { useLoadingIndicator as O } from "../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
18
+ const U = (t) => t.map((n) => n.message ? /* @__PURE__ */ o("li", { children: n.message }, n.key) : null), k = (t, n) => {
19
+ const m = n ? n + "." : "";
20
+ if (t.category === "invalid_attribute_value" || t.category === "invalid_operation")
21
21
  return [
22
22
  {
23
- key: w(m + e.errorKey),
24
- message: e.message ?? ""
23
+ key: w(m + t.errorKey),
24
+ message: t.message ?? ""
25
25
  }
26
26
  ];
27
- if (e.category === "nested_errors" && e.errors !== void 0) {
28
- let a = "";
29
- return e.metadata?.key && typeof e.metadata.key == "string" ? a = e.metadata.key : e.metadata?.state && typeof e.metadata.state == "string" ? a = e.metadata.state : e.errorKey && (a = e.errorKey), e.errors.flatMap((t) => h(t, m + a));
27
+ if (t.category === "nested_errors" && t.errors !== void 0) {
28
+ let s = "";
29
+ return t.metadata?.key && typeof t.metadata.key == "string" ? s = t.metadata.key : t.metadata?.state && typeof t.metadata.state == "string" ? s = t.metadata.state : t.errorKey && (s = t.errorKey), t.errors.flatMap((r) => k(r, m + s));
30
30
  }
31
31
  return [];
32
- }, re = ({
33
- children: e,
34
- FallbackComponent: o = P,
32
+ }, ot = ({
33
+ children: t,
34
+ FallbackComponent: n = P,
35
35
  LoaderComponent: m,
36
- onEvent: a
36
+ onEvent: s
37
37
  }) => {
38
- const [t, l] = y(null), [c, p] = y(null), f = K(), { t: k } = S(), d = F(), { LoadingIndicator: x } = M(), b = m ?? x, v = (n) => {
39
- l(n), n instanceof C && Array.isArray(n.errors) && p(n.errors.flatMap((s) => h(s)));
40
- }, I = A(
41
- async (n, s) => {
42
- l(null), p(null);
38
+ const [r, l] = y(null), [c, f] = y(null), p = K(), { t: x } = B(), d = M(), { LoadingIndicator: b } = O(), v = m ?? b, I = E((e) => {
39
+ l(e), e || f(null);
40
+ }, []), A = (e) => {
41
+ l(e), e instanceof h && Array.isArray(e.errors) && f(e.errors.flatMap((a) => k(a)));
42
+ }, L = E(
43
+ async (e, a) => {
44
+ l(null), f(null);
43
45
  try {
44
- await s(n);
46
+ await a(e);
45
47
  } catch (i) {
46
- i instanceof E || i instanceof g || i instanceof C ? v(i) : f(i);
48
+ i instanceof g || i instanceof C || i instanceof h ? A(i) : p(i);
47
49
  }
48
50
  },
49
- [l, f]
51
+ [l, p]
50
52
  );
51
- return /* @__PURE__ */ r(
52
- _.Provider,
53
+ return /* @__PURE__ */ o(
54
+ j.Provider,
53
55
  {
54
56
  value: {
55
57
  fieldErrors: c,
56
- setError: l,
57
- onEvent: a,
58
- throwError: f,
59
- baseSubmitHandler: I
58
+ setError: I,
59
+ onEvent: s,
60
+ throwError: p,
61
+ baseSubmitHandler: L
60
62
  },
61
- children: /* @__PURE__ */ r(B, { children: ({ reset: n }) => /* @__PURE__ */ u(
62
- R,
63
+ children: /* @__PURE__ */ o(T, { children: ({ reset: e }) => /* @__PURE__ */ u(
64
+ S,
63
65
  {
64
- FallbackComponent: o,
65
- onReset: n,
66
- onError: (s) => {
67
- a(j.ERROR, s);
66
+ FallbackComponent: n,
67
+ onReset: e,
68
+ onError: (a) => {
69
+ s(F.ERROR, a);
68
70
  },
69
71
  children: [
70
- (t || c) && /* @__PURE__ */ u(d.Alert, { label: k("status.errorEncountered"), status: "error", children: [
71
- c && /* @__PURE__ */ r(d.UnorderedList, { items: O(c) }),
72
- t && t instanceof E && /* @__PURE__ */ r(d.Text, { children: t.message }),
73
- t && t instanceof g && /* @__PURE__ */ r(d.Text, { as: "pre", children: t.pretty() })
72
+ (r || c) && /* @__PURE__ */ u(d.Alert, { label: x("status.errorEncountered"), status: "error", children: [
73
+ c && /* @__PURE__ */ o(d.UnorderedList, { items: U(c) }),
74
+ r && r instanceof g && /* @__PURE__ */ o(d.Text, { children: r.message }),
75
+ r && r instanceof C && /* @__PURE__ */ o(d.Text, { as: "pre", children: r.pretty() })
74
76
  ] }),
75
- /* @__PURE__ */ r(L, { fallback: /* @__PURE__ */ r(b, {}), children: /* @__PURE__ */ r(T, { children: e }) })
77
+ /* @__PURE__ */ o(R, { fallback: /* @__PURE__ */ o(v, {}), children: /* @__PURE__ */ o(_, { children: t }) })
76
78
  ]
77
79
  }
78
80
  ) })
@@ -80,6 +82,6 @@ const O = (e) => e.map((o) => o.message ? /* @__PURE__ */ r("li", { children: o.
80
82
  );
81
83
  };
82
84
  export {
83
- re as BaseComponent
85
+ ot as BaseComponent
84
86
  };
85
87
  //# sourceMappingURL=Base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Base.js","sources":["../../../src/components/Base/Base.tsx"],"sourcesContent":["import type { ReactNode, JSX } from 'react'\nimport { Suspense, useState, useCallback } from 'react'\nimport type { FallbackProps } from 'react-error-boundary'\nimport { ErrorBoundary } from 'react-error-boundary'\nimport { useTranslation } from 'react-i18next'\nimport { APIError } from '@gusto/embedded-api/models/errors/apierror'\nimport { SDKValidationError } from '@gusto/embedded-api/models/errors/sdkvalidationerror'\nimport { UnprocessableEntityErrorObject } from '@gusto/embedded-api/models/errors/unprocessableentityerrorobject'\nimport type { EntityErrorObject } from '@gusto/embedded-api/models/components/entityerrorobject'\nimport { QueryErrorResetBoundary } from '@tanstack/react-query'\nimport { FadeIn } from '../Common/FadeIn/FadeIn'\nimport { BaseContext, type FieldError, type KnownErrors, type OnEventType } from './useBase'\nimport { componentEvents, type EventType } from '@/shared/constants'\nimport { InternalError, useAsyncError } from '@/components/Common'\nimport { snakeCaseToCamelCase } from '@/helpers/formattedStrings'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport type { ResourceDictionary, Resources } from '@/types/Helpers'\nimport { useLoadingIndicator } from '@/contexts/LoadingIndicatorProvider/useLoadingIndicator'\nimport type { LoadingIndicatorContextProps } from '@/contexts/LoadingIndicatorProvider/useLoadingIndicator'\n\nexport interface CommonComponentInterface<TResourceKey extends keyof Resources = keyof Resources> {\n children?: ReactNode\n className?: string\n defaultValues?: unknown\n dictionary?: ResourceDictionary<TResourceKey>\n}\n\n// Base component wrapper with error and suspense handling\nexport interface BaseComponentInterface<TResourceKey extends keyof Resources = keyof Resources>\n extends CommonComponentInterface<TResourceKey> {\n FallbackComponent?: (props: FallbackProps) => JSX.Element\n LoaderComponent?: LoadingIndicatorContextProps['LoadingIndicator']\n onEvent: OnEventType<EventType, unknown>\n}\n\n/**Traverses errorList and finds items with message properties */\nconst renderErrorList = (errorList: FieldError[]): React.ReactNode[] => {\n return errorList.map(errorFromList => {\n if (errorFromList.message) {\n return <li key={errorFromList.key}>{errorFromList.message}</li>\n }\n return null\n })\n}\n/**Recuresively parses error list and constructs an array of objects containing attribute value error messages associated with form fields. Nested errors construct '.' separated keys\n * metadata.state is a special case for state taxes validation errors\n */\nconst getFieldErrors = (\n error: EntityErrorObject,\n parentKey?: string,\n): { key: string; message: string }[] => {\n const keyPrefix = parentKey ? parentKey + '.' : ''\n if (error.category === 'invalid_attribute_value' || error.category === 'invalid_operation') {\n return [\n {\n key: snakeCaseToCamelCase(keyPrefix + error.errorKey),\n message: error.message ?? '',\n },\n ]\n }\n if (error.category === 'nested_errors' && error.errors !== undefined) {\n //TODO: clean this up once Metadata type is fixed in openapi spec\n let keySuffix = ''\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n if (error.metadata?.key && typeof error.metadata.key === 'string') {\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n keySuffix = error.metadata.key as string\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n } else if (error.metadata?.state && typeof error.metadata.state === 'string') {\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n keySuffix = error.metadata.state as string\n } else if (error.errorKey) {\n keySuffix = error.errorKey\n }\n return error.errors.flatMap(err => getFieldErrors(err, keyPrefix + keySuffix))\n }\n return []\n}\n\ntype SubmitHandler<T> = (data: T) => Promise<void>\n\nexport const BaseComponent = <TResourceKey extends keyof Resources = keyof Resources>({\n children,\n FallbackComponent = InternalError,\n LoaderComponent: LoadingIndicatorFromProps,\n onEvent,\n}: BaseComponentInterface<TResourceKey>) => {\n const [error, setError] = useState<KnownErrors | null>(null)\n const [fieldErrors, setFieldErrors] = useState<FieldError[] | null>(null)\n const throwError = useAsyncError()\n const { t } = useTranslation()\n const Components = useComponentContext()\n\n const { LoadingIndicator: LoadingIndicatorFromContext } = useLoadingIndicator()\n\n const LoaderComponent = LoadingIndicatorFromProps ?? LoadingIndicatorFromContext\n\n const processError = (error: KnownErrors) => {\n setError(error)\n //422\tapplication/json - content relaited error\n if (error instanceof UnprocessableEntityErrorObject && Array.isArray(error.errors)) {\n setFieldErrors(error.errors.flatMap(err => getFieldErrors(err)))\n }\n }\n\n const baseSubmitHandler = useCallback(\n async <T,>(data: T, componentHandler: SubmitHandler<T>) => {\n setError(null)\n setFieldErrors(null)\n try {\n await componentHandler(data)\n } catch (err) {\n if (\n err instanceof APIError ||\n err instanceof SDKValidationError ||\n err instanceof UnprocessableEntityErrorObject\n ) {\n processError(err)\n } else throwError(err)\n }\n },\n [setError, throwError],\n )\n\n return (\n <BaseContext.Provider\n value={{\n fieldErrors,\n setError,\n onEvent,\n throwError,\n baseSubmitHandler,\n }}\n >\n <QueryErrorResetBoundary>\n {({ reset: resetQueries }) => (\n <ErrorBoundary\n FallbackComponent={FallbackComponent}\n onReset={resetQueries}\n onError={err => {\n onEvent(componentEvents.ERROR, err)\n }}\n >\n {(error || fieldErrors) && (\n <Components.Alert label={t('status.errorEncountered')} status=\"error\">\n {fieldErrors && <Components.UnorderedList items={renderErrorList(fieldErrors)} />}\n {error && error instanceof APIError && (\n <Components.Text>{error.message}</Components.Text>\n )}\n {error && error instanceof SDKValidationError && (\n <Components.Text as=\"pre\">{error.pretty()}</Components.Text>\n )}\n </Components.Alert>\n )}\n <Suspense fallback={<LoaderComponent />}>\n <FadeIn>{children}</FadeIn>\n </Suspense>\n </ErrorBoundary>\n )}\n </QueryErrorResetBoundary>\n </BaseContext.Provider>\n )\n}\n"],"names":["renderErrorList","errorList","errorFromList","jsx","getFieldErrors","error","parentKey","keyPrefix","snakeCaseToCamelCase","keySuffix","err","BaseComponent","children","FallbackComponent","InternalError","LoadingIndicatorFromProps","onEvent","setError","useState","fieldErrors","setFieldErrors","throwError","useAsyncError","t","useTranslation","Components","useComponentContext","LoadingIndicatorFromContext","useLoadingIndicator","LoaderComponent","processError","UnprocessableEntityErrorObject","baseSubmitHandler","useCallback","data","componentHandler","APIError","SDKValidationError","BaseContext","QueryErrorResetBoundary","resetQueries","jsxs","ErrorBoundary","componentEvents","Suspense","FadeIn"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,MAAMA,IAAkB,CAACC,MAChBA,EAAU,IAAI,CAAiBC,MAChCA,EAAc,UACR,gBAAAC,EAAA,MAAA,EAA4B,UAAcD,EAAA,QAAA,GAAlCA,EAAc,GAA4B,IAErD,IACR,GAKGE,IAAiB,CACrBC,GACAC,MACuC;AACjC,QAAAC,IAAYD,IAAYA,IAAY,MAAM;AAChD,MAAID,EAAM,aAAa,6BAA6BA,EAAM,aAAa;AAC9D,WAAA;AAAA,MACL;AAAA,QACE,KAAKG,EAAqBD,IAAYF,EAAM,QAAQ;AAAA,QACpD,SAASA,EAAM,WAAW;AAAA,MAAA;AAAA,IAE9B;AAEF,MAAIA,EAAM,aAAa,mBAAmBA,EAAM,WAAW,QAAW;AAEpE,QAAII,IAAY;AAEhB,WAAIJ,EAAM,UAAU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AAnB;AAAA,QACA,UAAAF;AAAA,QACA,SAAAD;AAAA,QACA,YAAAK;AAAA,QACA,mBAAAW;AAAA,MACF;AAAA,MAEA,4BAACO,GACE,EAAA,UAAA,CAAC,EAAE,OAAOC,QACT,gBAAAC;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,mBAAA7B;AAAA,UACA,SAAS2B;AAAA,UACT,SAAS,CAAO9B,MAAA;AACN,YAAAM,EAAA2B,EAAgB,OAAOjC,CAAG;AAAA,UACpC;AAAA,UAEE,UAAA;AAAA,aAASL,KAAAc,MACR,gBAAAsB,EAAAhB,EAAW,OAAX,EAAiB,OAAOF,EAAE,yBAAyB,GAAG,QAAO,SAC3D,UAAA;AAAA,cAAAJ,uBAAgBM,EAAW,eAAX,EAAyB,OAAOzB,EAAgBmB,CAAW,GAAG;AAAA,cAC9Ed,KAASA,aAAiB+B,KACzB,gBAAAjC,EAACsB,EAAW,MAAX,EAAiB,YAAM,SAAQ;AAAA,cAEjCpB,KAASA,aAAiBgC,KACxB,gBAAAlC,EAAAsB,EAAW,MAAX,EAAgB,IAAG,OAAO,UAAMpB,EAAA,OAAA,EAAS,CAAA;AAAA,YAAA,GAE9C;AAAA,YAEF,gBAAAF,EAACyC,KAAS,UAAU,gBAAAzC,EAAC0B,KAAgB,GACnC,UAAA,gBAAA1B,EAAC0C,GAAQ,EAAA,UAAAjC,EAAS,CAAA,EACpB,CAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA,EAGN,CAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
1
+ {"version":3,"file":"Base.js","sources":["../../../src/components/Base/Base.tsx"],"sourcesContent":["import type { ReactNode, JSX } from 'react'\nimport { Suspense, useState, useCallback } from 'react'\nimport type { FallbackProps } from 'react-error-boundary'\nimport { ErrorBoundary } from 'react-error-boundary'\nimport { useTranslation } from 'react-i18next'\nimport { APIError } from '@gusto/embedded-api/models/errors/apierror'\nimport { SDKValidationError } from '@gusto/embedded-api/models/errors/sdkvalidationerror'\nimport { UnprocessableEntityErrorObject } from '@gusto/embedded-api/models/errors/unprocessableentityerrorobject'\nimport type { EntityErrorObject } from '@gusto/embedded-api/models/components/entityerrorobject'\nimport { QueryErrorResetBoundary } from '@tanstack/react-query'\nimport { FadeIn } from '../Common/FadeIn/FadeIn'\nimport { BaseContext, type FieldError, type KnownErrors, type OnEventType } from './useBase'\nimport { componentEvents, type EventType } from '@/shared/constants'\nimport { InternalError, useAsyncError } from '@/components/Common'\nimport { snakeCaseToCamelCase } from '@/helpers/formattedStrings'\nimport { useComponentContext } from '@/contexts/ComponentAdapter/useComponentContext'\nimport type { ResourceDictionary, Resources } from '@/types/Helpers'\nimport { useLoadingIndicator } from '@/contexts/LoadingIndicatorProvider/useLoadingIndicator'\nimport type { LoadingIndicatorContextProps } from '@/contexts/LoadingIndicatorProvider/useLoadingIndicator'\n\nexport interface CommonComponentInterface<TResourceKey extends keyof Resources = keyof Resources> {\n children?: ReactNode\n className?: string\n defaultValues?: unknown\n dictionary?: ResourceDictionary<TResourceKey>\n}\n\n// Base component wrapper with error and suspense handling\nexport interface BaseComponentInterface<TResourceKey extends keyof Resources = keyof Resources>\n extends CommonComponentInterface<TResourceKey> {\n FallbackComponent?: (props: FallbackProps) => JSX.Element\n LoaderComponent?: LoadingIndicatorContextProps['LoadingIndicator']\n onEvent: OnEventType<EventType, unknown>\n}\n\n/**Traverses errorList and finds items with message properties */\nconst renderErrorList = (errorList: FieldError[]): React.ReactNode[] => {\n return errorList.map(errorFromList => {\n if (errorFromList.message) {\n return <li key={errorFromList.key}>{errorFromList.message}</li>\n }\n return null\n })\n}\n/**Recuresively parses error list and constructs an array of objects containing attribute value error messages associated with form fields. Nested errors construct '.' separated keys\n * metadata.state is a special case for state taxes validation errors\n */\nconst getFieldErrors = (\n error: EntityErrorObject,\n parentKey?: string,\n): { key: string; message: string }[] => {\n const keyPrefix = parentKey ? parentKey + '.' : ''\n if (error.category === 'invalid_attribute_value' || error.category === 'invalid_operation') {\n return [\n {\n key: snakeCaseToCamelCase(keyPrefix + error.errorKey),\n message: error.message ?? '',\n },\n ]\n }\n if (error.category === 'nested_errors' && error.errors !== undefined) {\n //TODO: clean this up once Metadata type is fixed in openapi spec\n let keySuffix = ''\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n if (error.metadata?.key && typeof error.metadata.key === 'string') {\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n keySuffix = error.metadata.key as string\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n } else if (error.metadata?.state && typeof error.metadata.state === 'string') {\n //@ts-expect-error: Metadata in speakeasy is incorrectly typed\n keySuffix = error.metadata.state as string\n } else if (error.errorKey) {\n keySuffix = error.errorKey\n }\n return error.errors.flatMap(err => getFieldErrors(err, keyPrefix + keySuffix))\n }\n return []\n}\n\ntype SubmitHandler<T> = (data: T) => Promise<void>\n\nexport const BaseComponent = <TResourceKey extends keyof Resources = keyof Resources>({\n children,\n FallbackComponent = InternalError,\n LoaderComponent: LoadingIndicatorFromProps,\n onEvent,\n}: BaseComponentInterface<TResourceKey>) => {\n const [error, setError] = useState<KnownErrors | null>(null)\n const [fieldErrors, setFieldErrors] = useState<FieldError[] | null>(null)\n const throwError = useAsyncError()\n const { t } = useTranslation()\n const Components = useComponentContext()\n\n const { LoadingIndicator: LoadingIndicatorFromContext } = useLoadingIndicator()\n\n const LoaderComponent = LoadingIndicatorFromProps ?? LoadingIndicatorFromContext\n\n // Enhanced setError that also clears fieldErrors when error is cleared\n const setErrorWithFieldsClear = useCallback((error: KnownErrors | null) => {\n setError(error)\n if (!error) {\n setFieldErrors(null)\n }\n }, [])\n\n const processError = (error: KnownErrors) => {\n setError(error)\n //422\tapplication/json - content relaited error\n if (error instanceof UnprocessableEntityErrorObject && Array.isArray(error.errors)) {\n setFieldErrors(error.errors.flatMap(err => getFieldErrors(err)))\n }\n }\n\n const baseSubmitHandler = useCallback(\n async <T,>(data: T, componentHandler: SubmitHandler<T>) => {\n setError(null)\n setFieldErrors(null)\n try {\n await componentHandler(data)\n } catch (err) {\n if (\n err instanceof APIError ||\n err instanceof SDKValidationError ||\n err instanceof UnprocessableEntityErrorObject\n ) {\n processError(err)\n } else throwError(err)\n }\n },\n [setError, throwError],\n )\n\n return (\n <BaseContext.Provider\n value={{\n fieldErrors,\n setError: setErrorWithFieldsClear,\n onEvent,\n throwError,\n baseSubmitHandler,\n }}\n >\n <QueryErrorResetBoundary>\n {({ reset: resetQueries }) => (\n <ErrorBoundary\n FallbackComponent={FallbackComponent}\n onReset={resetQueries}\n onError={err => {\n onEvent(componentEvents.ERROR, err)\n }}\n >\n {(error || fieldErrors) && (\n <Components.Alert label={t('status.errorEncountered')} status=\"error\">\n {fieldErrors && <Components.UnorderedList items={renderErrorList(fieldErrors)} />}\n {error && error instanceof APIError && (\n <Components.Text>{error.message}</Components.Text>\n )}\n {error && error instanceof SDKValidationError && (\n <Components.Text as=\"pre\">{error.pretty()}</Components.Text>\n )}\n </Components.Alert>\n )}\n <Suspense fallback={<LoaderComponent />}>\n <FadeIn>{children}</FadeIn>\n </Suspense>\n </ErrorBoundary>\n )}\n </QueryErrorResetBoundary>\n </BaseContext.Provider>\n )\n}\n"],"names":["renderErrorList","errorList","errorFromList","jsx","getFieldErrors","error","parentKey","keyPrefix","snakeCaseToCamelCase","keySuffix","err","BaseComponent","children","FallbackComponent","InternalError","LoadingIndicatorFromProps","onEvent","setError","useState","fieldErrors","setFieldErrors","throwError","useAsyncError","t","useTranslation","Components","useComponentContext","LoadingIndicatorFromContext","useLoadingIndicator","LoaderComponent","setErrorWithFieldsClear","useCallback","processError","UnprocessableEntityErrorObject","baseSubmitHandler","data","componentHandler","APIError","SDKValidationError","BaseContext","QueryErrorResetBoundary","resetQueries","jsxs","ErrorBoundary","componentEvents","Suspense","FadeIn"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,MAAMA,IAAkB,CAACC,MAChBA,EAAU,IAAI,CAAiBC,MAChCA,EAAc,UACR,gBAAAC,EAAA,MAAA,EAA4B,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A,GAE9C;AAAA,YAEF,gBAAAF,EAAC0C,KAAS,UAAU,gBAAA1C,EAAC0B,KAAgB,GACnC,UAAA,gBAAA1B,EAAC2C,GAAQ,EAAA,UAAAlC,EAAS,CAAA,EACpB,CAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA,EAGN,CAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
@@ -10,7 +10,7 @@ export type FieldError = {
10
10
  };
11
11
  interface BaseContextProps {
12
12
  fieldErrors: FieldError[] | null;
13
- setError: (err: KnownErrors) => void;
13
+ setError: (err: KnownErrors | null) => void;
14
14
  onEvent: OnEventType<EventType, unknown>;
15
15
  throwError: (e: unknown) => void;
16
16
  baseSubmitHandler: <T>(formData: T, componentHandler: (payload: T) => Promise<void>) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"useBase.js","sources":["../../../src/components/Base/useBase.tsx"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport type { APIError } from '@gusto/embedded-api/models/errors/apierror'\nimport type { SDKValidationError } from '@gusto/embedded-api/models/errors/sdkvalidationerror'\nimport type { UnprocessableEntityErrorObject } from '@gusto/embedded-api/models/errors/unprocessableentityerrorobject'\nimport { type EventType } from '@/shared/constants'\n\nexport type OnEventType<K, T> = (type: K, data?: T) => void\n\nexport type KnownErrors = APIError | SDKValidationError | UnprocessableEntityErrorObject\n\nexport type FieldError = {\n key: string\n message: string\n}\n\ninterface BaseContextProps {\n fieldErrors: FieldError[] | null\n setError: (err: KnownErrors) => void\n onEvent: OnEventType<EventType, unknown>\n throwError: (e: unknown) => void\n baseSubmitHandler: <T>(\n formData: T,\n componentHandler: (payload: T) => Promise<void>,\n ) => Promise<void>\n}\n\nexport const BaseContext = createContext<BaseContextProps | undefined>(undefined)\n\nexport const useBase = () => {\n const context = useContext(BaseContext)\n if (!context) {\n throw new Error('useBase must be used within a BaseProvider')\n }\n return context\n}\n"],"names":["BaseContext","createContext","useBase","context","useContext"],"mappings":";AA0Ba,MAAAA,IAAcC,EAA4C,MAAS,GAEnEC,IAAU,MAAM;AACrB,QAAAC,IAAUC,EAAWJ,CAAW;AACtC,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,4CAA4C;AAEvD,SAAAA;AACT;"}
1
+ {"version":3,"file":"useBase.js","sources":["../../../src/components/Base/useBase.tsx"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport type { APIError } from '@gusto/embedded-api/models/errors/apierror'\nimport type { SDKValidationError } from '@gusto/embedded-api/models/errors/sdkvalidationerror'\nimport type { UnprocessableEntityErrorObject } from '@gusto/embedded-api/models/errors/unprocessableentityerrorobject'\nimport { type EventType } from '@/shared/constants'\n\nexport type OnEventType<K, T> = (type: K, data?: T) => void\n\nexport type KnownErrors = APIError | SDKValidationError | UnprocessableEntityErrorObject\n\nexport type FieldError = {\n key: string\n message: string\n}\n\ninterface BaseContextProps {\n fieldErrors: FieldError[] | null\n setError: (err: KnownErrors | null) => void\n onEvent: OnEventType<EventType, unknown>\n throwError: (e: unknown) => void\n baseSubmitHandler: <T>(\n formData: T,\n componentHandler: (payload: T) => Promise<void>,\n ) => Promise<void>\n}\n\nexport const BaseContext = createContext<BaseContextProps | undefined>(undefined)\n\nexport const useBase = () => {\n const context = useContext(BaseContext)\n if (!context) {\n throw new Error('useBase must be used within a BaseProvider')\n }\n return context\n}\n"],"names":["BaseContext","createContext","useBase","context","useContext"],"mappings":";AA0Ba,MAAAA,IAAcC,EAA4C,MAAS,GAEnEC,IAAU,MAAM;AACrB,QAAAC,IAAUC,EAAWJ,CAAW;AACtC,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,4CAA4C;AAEvD,SAAAA;AACT;"}
@@ -1,21 +1,21 @@
1
- import { jsx as t, jsxs as G } from "react/jsx-runtime";
2
- import { useForm as z, FormProvider as J } from "react-hook-form";
3
- import { zodResolver as K } from "@hookform/resolvers/zod";
1
+ import { jsx as t, jsxs as J } from "react/jsx-runtime";
2
+ import { useForm as K, FormProvider as Q } from "react-hook-form";
3
+ import { zodResolver as W } from "@hookform/resolvers/zod";
4
4
  import { useState as A, useEffect as _ } from "react";
5
- import { usePaySchedulesGetPreview as Q } from "@gusto/embedded-api/react-query/paySchedulesGetPreview";
6
- import { usePaySchedulesUpdateMutation as W } from "@gusto/embedded-api/react-query/paySchedulesUpdate";
7
- import { usePaySchedulesGetAllSuspense as X } from "@gusto/embedded-api/react-query/paySchedulesGetAll";
8
- import { usePaySchedulesCreateMutation as Z } from "@gusto/embedded-api/react-query/paySchedulesCreate";
9
- import { PayScheduleSchema as $, PayScheduleProvider as V } from "./usePaySchedule.js";
10
- import { Form as ee } from "../../Common/Form/Form.js";
11
- import { BaseComponent as oe } from "../../Base/Base.js";
12
- import { useBase as re } from "../../Base/useBase.js";
13
- import { Flex as ae } from "../../Common/Flex/Flex.js";
5
+ import { usePaySchedulesGetPreview as X } from "@gusto/embedded-api/react-query/paySchedulesGetPreview";
6
+ import { usePaySchedulesUpdateMutation as Z } from "@gusto/embedded-api/react-query/paySchedulesUpdate";
7
+ import { usePaySchedulesGetAllSuspense as $ } from "@gusto/embedded-api/react-query/paySchedulesGetAll";
8
+ import { usePaySchedulesCreateMutation as V } from "@gusto/embedded-api/react-query/paySchedulesCreate";
9
+ import { PayScheduleSchema as ee, PayScheduleProvider as oe } from "./usePaySchedule.js";
10
+ import { Form as re } from "../../Common/Form/Form.js";
11
+ import { BaseComponent as ae } from "../../Base/Base.js";
12
+ import { useBase as te } from "../../Base/useBase.js";
13
+ import { Flex as ne } from "../../Common/Flex/Flex.js";
14
14
  import "react-i18next";
15
15
  import "classnames";
16
- import { useI18n as te, useComponentDictionary as ne } from "../../../i18n/I18n.js";
16
+ import { useI18n as ce, useComponentDictionary as ie } from "../../../i18n/I18n.js";
17
17
  import { componentEvents as p } from "../../../shared/constants.js";
18
- import { formatDateToStringDate as v } from "../../../helpers/dateFormatting.js";
18
+ import { formatDateToStringDate as l } from "../../../helpers/dateFormatting.js";
19
19
  import { Head as w } from "./_parts/Head.js";
20
20
  import { List as C } from "./_parts/List.js";
21
21
  import { Edit as L } from "./_parts/Edit.js";
@@ -25,8 +25,8 @@ const u = ({
25
25
  defaultValues: s,
26
26
  dictionary: a,
27
27
  ...P
28
- }) => (te("Company.PaySchedule"), ne("Company.PaySchedule", a), /* @__PURE__ */ t(oe, { ...P, children: /* @__PURE__ */ t(ce, { companyId: n, defaultValues: s, children: P.children }) })), ce = ({ companyId: n, children: s, defaultValues: a }) => {
29
- const { baseSubmitHandler: P, onEvent: h, fieldErrors: f } = re(), [i, m] = A("LIST_PAY_SCHEDULES"), [E, T] = A(null), O = {
28
+ }) => (ce("Company.PaySchedule"), ie("Company.PaySchedule", a), /* @__PURE__ */ t(ae, { ...P, children: /* @__PURE__ */ t(de, { companyId: n, defaultValues: s, children: P.children }) })), de = ({ companyId: n, children: s, defaultValues: a }) => {
29
+ const { baseSubmitHandler: P, onEvent: h, fieldErrors: f, setError: T } = te(), [i, m] = A("LIST_PAY_SCHEDULES"), [E, O] = A(null), H = {
30
30
  frequency: a?.frequency ?? "Every week",
31
31
  anchorPayDate: a?.anchorPayDate ? new Date(a.anchorPayDate) : void 0,
32
32
  anchorEndOfPayPeriod: a?.anchorEndOfPayPeriod ? new Date(a.anchorEndOfPayPeriod) : void 0,
@@ -35,23 +35,23 @@ const u = ({
35
35
  customName: a?.customName ?? "",
36
36
  customTwicePerMonth: "false",
37
37
  payPeriodPreviewRange: 0
38
- }, { data: H } = X({
38
+ }, { data: U } = $({
39
39
  companyId: n
40
- }), U = Z(), M = W(), D = z({
41
- resolver: K($),
42
- defaultValues: O
43
- }), { watch: Y, setValue: S, reset: d, setError: l } = D;
40
+ }), M = V(), Y = Z(), D = K({
41
+ resolver: W(ee),
42
+ defaultValues: H
43
+ }), { watch: N, setValue: S, reset: d, clearErrors: b, setError: v } = D;
44
44
  _(() => {
45
45
  f && f.forEach((o) => {
46
- l(o.key, { message: o.message });
46
+ v(o.key, { message: o.message });
47
47
  });
48
- }, [l, f]);
49
- const e = Y(), N = e.anchorPayDate && v(e.anchorPayDate) || "", b = e.anchorEndOfPayPeriod && v(e.anchorEndOfPayPeriod) || "", { data: g, isLoading: R } = Q(
48
+ }, [v, f]);
49
+ const e = N(), g = e.anchorPayDate && l(e.anchorPayDate) || "", B = e.anchorEndOfPayPeriod && l(e.anchorEndOfPayPeriod) || "", { data: R, isLoading: x } = X(
50
50
  {
51
51
  companyId: n,
52
52
  frequency: e.frequency,
53
- anchorPayDate: N,
54
- anchorEndOfPayPeriod: b,
53
+ anchorPayDate: g,
54
+ anchorEndOfPayPeriod: B,
55
55
  day1: e.day1 ?? void 0,
56
56
  day2: e.day2 ?? void 0
57
57
  },
@@ -62,11 +62,11 @@ const u = ({
62
62
  _(() => {
63
63
  e.frequency === "Twice per month" && e.day1 === 15 && e.day2 === 31 && e.customTwicePerMonth === void 0 ? S("customTwicePerMonth", "1st15th") : e.frequency === "Twice per month" && e.customTwicePerMonth === void 0 && S("customTwicePerMonth", "custom");
64
64
  }, [e.frequency, e.day1, e.day2, S, e.customTwicePerMonth]);
65
- const x = () => {
65
+ const F = () => {
66
66
  m("ADD_PAY_SCHEDULE"), d({});
67
- }, B = () => {
68
- m("LIST_PAY_SCHEDULES"), d({});
69
- }, F = (o) => {
67
+ }, I = () => {
68
+ m("LIST_PAY_SCHEDULES"), d({}), b(), T(null);
69
+ }, j = (o) => {
70
70
  d({
71
71
  frequency: o.frequency,
72
72
  anchorPayDate: o.anchorPayDate ? new Date(o.anchorPayDate) : void 0,
@@ -74,14 +74,14 @@ const u = ({
74
74
  day1: o.day1 ?? void 0,
75
75
  day2: o.day2 ?? void 0,
76
76
  customName: o.customName ?? ""
77
- }), T(o), m("EDIT_PAY_SCHEDULE");
78
- }, I = () => {
77
+ }), O(o), m("EDIT_PAY_SCHEDULE");
78
+ }, k = () => {
79
79
  h(p.PAY_SCHEDULE_DONE);
80
- }, j = async (o) => {
80
+ }, G = async (o) => {
81
81
  await P(o, async (r) => {
82
- const y = (c) => c && v(c) || "";
82
+ const y = (c) => c && l(c) || "";
83
83
  if (i === "ADD_PAY_SCHEDULE") {
84
- const c = await U.mutateAsync({
84
+ const c = await M.mutateAsync({
85
85
  request: {
86
86
  companyId: n,
87
87
  requestBody: {
@@ -96,7 +96,7 @@ const u = ({
96
96
  });
97
97
  h(p.PAY_SCHEDULE_CREATED, c), d();
98
98
  } else if (i === "EDIT_PAY_SCHEDULE") {
99
- const c = E?.version, k = await M.mutateAsync({
99
+ const c = E?.version, z = await Y.mutateAsync({
100
100
  request: {
101
101
  payScheduleId: E?.uuid,
102
102
  companyId: n,
@@ -111,27 +111,27 @@ const u = ({
111
111
  }
112
112
  }
113
113
  });
114
- h(p.PAY_SCHEDULE_UPDATED, k), d();
114
+ h(p.PAY_SCHEDULE_UPDATED, z), d();
115
115
  }
116
116
  m("LIST_PAY_SCHEDULES");
117
117
  });
118
118
  };
119
119
  return /* @__PURE__ */ t(
120
- V,
120
+ oe,
121
121
  {
122
122
  value: {
123
123
  companyId: n,
124
- handleAdd: x,
125
- handleEdit: F,
126
- handleCancel: B,
127
- handleContinue: I,
124
+ handleAdd: F,
125
+ handleEdit: j,
126
+ handleCancel: I,
127
+ handleContinue: k,
128
128
  mode: i,
129
- paySchedules: H.payScheduleList,
130
- payPeriodPreview: g?.object?.payPeriods,
131
- payPreviewLoading: R,
129
+ paySchedules: U.payScheduleList,
130
+ payPeriodPreview: R?.object?.payPeriods,
131
+ payPreviewLoading: x,
132
132
  currentPaySchedule: E
133
133
  },
134
- children: /* @__PURE__ */ t("span", { "data-testid": "pay-schedule-edit-form", children: /* @__PURE__ */ t(J, { ...D, children: /* @__PURE__ */ t(ee, { onSubmit: D.handleSubmit(j), children: s || /* @__PURE__ */ G(ae, { flexDirection: "column", children: [
134
+ children: /* @__PURE__ */ t("span", { "data-testid": "pay-schedule-edit-form", children: /* @__PURE__ */ t(Q, { ...D, children: /* @__PURE__ */ t(re, { onSubmit: D.handleSubmit(G), children: s || /* @__PURE__ */ J(ne, { flexDirection: "column", children: [
135
135
  /* @__PURE__ */ t(w, {}),
136
136
  /* @__PURE__ */ t(C, {}),
137
137
  /* @__PURE__ */ t(L, {}),
@@ -1 +1 @@
1
- {"version":3,"file":"PaySchedule.js","sources":["../../../../src/components/Company/PaySchedule/PaySchedule.tsx"],"sourcesContent":["import type { SubmitHandler } from 'react-hook-form'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useEffect, useState } from 'react'\nimport { usePaySchedulesGetPreview } from '@gusto/embedded-api/react-query/paySchedulesGetPreview'\nimport { usePaySchedulesUpdateMutation } from '@gusto/embedded-api/react-query/paySchedulesUpdate'\nimport { usePaySchedulesGetAllSuspense } from '@gusto/embedded-api/react-query/paySchedulesGetAll'\nimport { usePaySchedulesCreateMutation } from '@gusto/embedded-api/react-query/paySchedulesCreate'\nimport type { PayScheduleObject as PayScheduleType } from '@gusto/embedded-api/models/components/payscheduleobject'\nimport type { Frequency } from '@gusto/embedded-api/models/operations/postv1companiescompanyidpayschedules'\nimport type { MODE, PayScheduleInputs, PayScheduleOutputs } from './usePaySchedule'\nimport {\n PayScheduleProvider,\n PayScheduleSchema,\n type PayScheduleDefaultValues,\n} from './usePaySchedule'\nimport { Actions, Edit, Head, List } from './_parts'\nimport { Form } from '@/components/Common/Form'\nimport type { BaseComponentInterface, CommonComponentInterface } from '@/components/Base'\nimport { BaseComponent, useBase } from '@/components/Base'\nimport { Flex } from '@/components/Common'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\nimport { useComponentDictionary } from '@/i18n/I18n'\n\ninterface PayScheduleProps extends CommonComponentInterface<'Company.PaySchedule'> {\n companyId: string\n defaultValues?: PayScheduleDefaultValues\n}\n\nexport const PaySchedule = ({\n companyId,\n defaultValues,\n dictionary,\n ...props\n}: PayScheduleProps & BaseComponentInterface) => {\n useI18n('Company.PaySchedule')\n useComponentDictionary('Company.PaySchedule', dictionary)\n return (\n <BaseComponent {...props}>\n <Root companyId={companyId} defaultValues={defaultValues}>\n {props.children}\n </Root>\n </BaseComponent>\n )\n}\n\nconst Root = ({ companyId, children, defaultValues }: PayScheduleProps) => {\n const { baseSubmitHandler, onEvent, fieldErrors } = useBase()\n const [mode, setMode] = useState<MODE>('LIST_PAY_SCHEDULES')\n const [currentPaySchedule, setCurrentPaySchedule] = useState<PayScheduleType | null>(null)\n const transformedDefaultValues: PayScheduleInputs = {\n frequency: defaultValues?.frequency ?? 'Every week',\n anchorPayDate: defaultValues?.anchorPayDate ? new Date(defaultValues.anchorPayDate) : undefined,\n anchorEndOfPayPeriod: defaultValues?.anchorEndOfPayPeriod\n ? new Date(defaultValues.anchorEndOfPayPeriod)\n : undefined,\n day1: defaultValues?.day1 ?? undefined,\n day2: defaultValues?.day2 ?? undefined,\n customName: defaultValues?.customName ?? '',\n customTwicePerMonth: 'false',\n payPeriodPreviewRange: 0,\n }\n\n const { data: paySchedules } = usePaySchedulesGetAllSuspense({\n companyId,\n })\n\n const createPayScheduleMutation = usePaySchedulesCreateMutation()\n const updatePayScheduleMutation = usePaySchedulesUpdateMutation()\n\n const formMethods = useForm<PayScheduleInputs, unknown, PayScheduleOutputs>({\n resolver: zodResolver(PayScheduleSchema),\n defaultValues: transformedDefaultValues,\n })\n const { watch, setValue, reset, setError } = formMethods\n\n useEffect(() => {\n if (fieldErrors) {\n // TODO: These error messages are not being localized correctly\n fieldErrors.forEach(error => {\n setError(error.key as keyof PayScheduleInputs, { message: error.message })\n })\n }\n }, [setError, fieldErrors])\n\n const allValues = watch()\n\n const formattedAnchorPayDate = allValues.anchorPayDate\n ? formatDateToStringDate(allValues.anchorPayDate) || ''\n : ''\n const formattedAnchorEndOfPayPeriod = allValues.anchorEndOfPayPeriod\n ? formatDateToStringDate(allValues.anchorEndOfPayPeriod) || ''\n : ''\n\n const { data: payPreviewData, isLoading } = usePaySchedulesGetPreview(\n {\n companyId,\n frequency: allValues.frequency,\n anchorPayDate: formattedAnchorPayDate,\n anchorEndOfPayPeriod: formattedAnchorEndOfPayPeriod,\n day1: allValues.day1 ?? undefined,\n day2: allValues.day2 ?? undefined,\n },\n {\n enabled: Boolean(\n allValues.anchorPayDate &&\n allValues.anchorEndOfPayPeriod &&\n (mode === 'ADD_PAY_SCHEDULE' || mode === 'EDIT_PAY_SCHEDULE'),\n ),\n },\n )\n\n // Set the custom_twice_per_month value based on the frequency and day_1 and day_2 values as it is not set by the API call\n useEffect(() => {\n if (\n allValues.frequency === 'Twice per month' &&\n allValues.day1 === 15 &&\n allValues.day2 === 31 &&\n allValues.customTwicePerMonth === undefined\n ) {\n setValue('customTwicePerMonth', `1st15th`)\n } else if (\n allValues.frequency === 'Twice per month' &&\n allValues.customTwicePerMonth === undefined\n ) {\n setValue('customTwicePerMonth', `custom`)\n }\n }, [allValues.frequency, allValues.day1, allValues.day2, setValue, allValues.customTwicePerMonth])\n\n const handleAdd = () => {\n setMode('ADD_PAY_SCHEDULE')\n reset({})\n }\n const handleCancel = () => {\n setMode('LIST_PAY_SCHEDULES')\n reset({})\n }\n const handleEdit = (schedule: PayScheduleType) => {\n reset({\n frequency: schedule.frequency as Frequency,\n anchorPayDate: schedule.anchorPayDate ? new Date(schedule.anchorPayDate) : undefined,\n anchorEndOfPayPeriod: schedule.anchorEndOfPayPeriod\n ? new Date(schedule.anchorEndOfPayPeriod)\n : undefined,\n day1: schedule.day1 ?? undefined,\n day2: schedule.day2 ?? undefined,\n customName: schedule.customName ?? '',\n })\n setCurrentPaySchedule(schedule)\n setMode('EDIT_PAY_SCHEDULE')\n }\n const handleContinue = () => {\n onEvent(componentEvents.PAY_SCHEDULE_DONE)\n }\n const onSubmit: SubmitHandler<PayScheduleOutputs> = async data => {\n await baseSubmitHandler(data, async payload => {\n const formatPayloadDate = (date: Date | undefined): string => {\n return date ? formatDateToStringDate(date) || '' : ''\n }\n\n if (mode === 'ADD_PAY_SCHEDULE') {\n const createPayScheduleResponse = await createPayScheduleMutation.mutateAsync({\n request: {\n companyId,\n requestBody: {\n frequency: payload.frequency,\n anchorPayDate: formatPayloadDate(payload.anchorPayDate),\n anchorEndOfPayPeriod: formatPayloadDate(payload.anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1,\n day2: payload.day2,\n },\n },\n })\n onEvent(componentEvents.PAY_SCHEDULE_CREATED, createPayScheduleResponse)\n reset()\n } else if (mode === 'EDIT_PAY_SCHEDULE') {\n const version = currentPaySchedule?.version\n const updatePayScheduleResponse = await updatePayScheduleMutation.mutateAsync({\n request: {\n payScheduleId: currentPaySchedule?.uuid as string,\n companyId,\n requestBody: {\n frequency: payload.frequency,\n anchorPayDate: formatPayloadDate(payload.anchorPayDate),\n anchorEndOfPayPeriod: formatPayloadDate(payload.anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1,\n day2: payload.day2,\n version: version as string,\n },\n },\n })\n onEvent(componentEvents.PAY_SCHEDULE_UPDATED, updatePayScheduleResponse)\n reset()\n }\n setMode('LIST_PAY_SCHEDULES')\n })\n }\n\n return (\n <PayScheduleProvider\n value={{\n companyId,\n handleAdd,\n handleEdit,\n handleCancel,\n handleContinue,\n mode,\n paySchedules: paySchedules.payScheduleList,\n payPeriodPreview: payPreviewData?.object?.payPeriods,\n payPreviewLoading: isLoading,\n currentPaySchedule,\n }}\n >\n <span data-testid=\"pay-schedule-edit-form\">\n <FormProvider {...formMethods}>\n <Form onSubmit={formMethods.handleSubmit(onSubmit)}>\n {children ? (\n children\n ) : (\n <Flex flexDirection=\"column\">\n <Head />\n <List />\n <Edit />\n <Actions />\n </Flex>\n )}\n </Form>\n </FormProvider>\n </span>\n </PayScheduleProvider>\n )\n}\n\nPaySchedule.Head = Head\nPaySchedule.List = List\nPaySchedule.Edit = Edit\nPaySchedule.Actions = Actions\n"],"names":["PaySchedule","companyId","defaultValues","dictionary","props","useI18n","useComponentDictionary","jsx","BaseComponent","Root","children","baseSubmitHandler","onEvent","fieldErrors","useBase","mode","setMode","useState","currentPaySchedule","setCurrentPaySchedule","transformedDefaultValues","paySchedules","usePaySchedulesGetAllSuspense","createPayScheduleMutation","usePaySchedulesCreateMutation","updatePayScheduleMutation","usePaySchedulesUpdateMutation","formMethods","useForm","zodResolver","PayScheduleSchema","watch","setValue","reset","setError","useEffect","error","allValues","formattedAnchorPayDate","formatDateToStringDate","formattedAnchorEndOfPayPeriod","payPreviewData","isLoading","usePaySchedulesGetPreview","handleAdd","handleCancel","handleEdit","schedule","handleContinue","componentEvents","onSubmit","data","payload","formatPayloadDate","date","createPayScheduleResponse","version","updatePayScheduleResponse","PayScheduleProvider","FormProvider","Form","jsxs","Flex","Head","List","Edit","Actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+BO,MAAMA,IAAc,CAAC;AAAA,EAC1B,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACL,OACEC,GAAQ,qBAAqB,GAC7BC,GAAuB,uBAAuBH,CAAU,GAEtD,gBAAAI,EAACC,IAAe,EAAA,GAAGJ,GACjB,UAAA,gBAAAG,EAACE,MAAK,WAAAR,GAAsB,eAAAC,GACzB,UAAME,EAAA,SAAA,CACT,EACF,CAAA,IAIEK,KAAO,CAAC,EAAE,WAAAR,GAAW,UAAAS,GAAU,eAAAR,QAAsC;AACzE,QAAM,EAAE,mBAAAS,GAAmB,SAAAC,GAAS,aAAAC,EAAA,IAAgBC,GAAQ,GACtD,CAACC,GAAMC,CAAO,IAAIC,EAAe,oBAAoB,GACrD,CAACC,GAAoBC,CAAqB,IAAIF,EAAiC,IAAI,GACnFG,IAA8C;AAAA,IAClD,WAAWlB,GAAe,aAAa;AAAA,IACvC,eAAeA,GAAe,gBAAgB,IAAI,KAAKA,EAAc,aAAa,IAAI;AAAA,IACtF,sBAAsBA,GAAe,uBACjC,IAAI,KAAKA,EAAc,oBAAoB,IAC3C;AAAA,IACJ,MAAMA,GAAe,QAAQ;AAAA,IAC7B,MAAMA,GAAe,QAAQ;AAAA,IAC7B,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AAA;AAAA,0BACLC,GAAQ,CAAA,CAAA;AAAA,MAAA,GACX,EAAA,CAEJ,GACF,EACF,CAAA;AAAA,IAAA;AAAA,EACF;AAEJ;AAEAlE,EAAY,OAAO+D;AACnB/D,EAAY,OAAOgE;AACnBhE,EAAY,OAAOiE;AACnBjE,EAAY,UAAUkE;"}
1
+ {"version":3,"file":"PaySchedule.js","sources":["../../../../src/components/Company/PaySchedule/PaySchedule.tsx"],"sourcesContent":["import type { SubmitHandler } from 'react-hook-form'\nimport { FormProvider, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { useEffect, useState } from 'react'\nimport { usePaySchedulesGetPreview } from '@gusto/embedded-api/react-query/paySchedulesGetPreview'\nimport { usePaySchedulesUpdateMutation } from '@gusto/embedded-api/react-query/paySchedulesUpdate'\nimport { usePaySchedulesGetAllSuspense } from '@gusto/embedded-api/react-query/paySchedulesGetAll'\nimport { usePaySchedulesCreateMutation } from '@gusto/embedded-api/react-query/paySchedulesCreate'\nimport type { PayScheduleObject as PayScheduleType } from '@gusto/embedded-api/models/components/payscheduleobject'\nimport type { Frequency } from '@gusto/embedded-api/models/operations/postv1companiescompanyidpayschedules'\nimport type { MODE, PayScheduleInputs, PayScheduleOutputs } from './usePaySchedule'\nimport {\n PayScheduleProvider,\n PayScheduleSchema,\n type PayScheduleDefaultValues,\n} from './usePaySchedule'\nimport { Actions, Edit, Head, List } from './_parts'\nimport { Form } from '@/components/Common/Form'\nimport type { BaseComponentInterface, CommonComponentInterface } from '@/components/Base'\nimport { BaseComponent, useBase } from '@/components/Base'\nimport { Flex } from '@/components/Common'\nimport { useI18n } from '@/i18n'\nimport { componentEvents } from '@/shared/constants'\nimport { formatDateToStringDate } from '@/helpers/dateFormatting'\nimport { useComponentDictionary } from '@/i18n/I18n'\n\ninterface PayScheduleProps extends CommonComponentInterface<'Company.PaySchedule'> {\n companyId: string\n defaultValues?: PayScheduleDefaultValues\n}\n\nexport const PaySchedule = ({\n companyId,\n defaultValues,\n dictionary,\n ...props\n}: PayScheduleProps & BaseComponentInterface) => {\n useI18n('Company.PaySchedule')\n useComponentDictionary('Company.PaySchedule', dictionary)\n return (\n <BaseComponent {...props}>\n <Root companyId={companyId} defaultValues={defaultValues}>\n {props.children}\n </Root>\n </BaseComponent>\n )\n}\n\nconst Root = ({ companyId, children, defaultValues }: PayScheduleProps) => {\n const { baseSubmitHandler, onEvent, fieldErrors, setError: setBaseError } = useBase()\n const [mode, setMode] = useState<MODE>('LIST_PAY_SCHEDULES')\n const [currentPaySchedule, setCurrentPaySchedule] = useState<PayScheduleType | null>(null)\n const transformedDefaultValues: PayScheduleInputs = {\n frequency: defaultValues?.frequency ?? 'Every week',\n anchorPayDate: defaultValues?.anchorPayDate ? new Date(defaultValues.anchorPayDate) : undefined,\n anchorEndOfPayPeriod: defaultValues?.anchorEndOfPayPeriod\n ? new Date(defaultValues.anchorEndOfPayPeriod)\n : undefined,\n day1: defaultValues?.day1 ?? undefined,\n day2: defaultValues?.day2 ?? undefined,\n customName: defaultValues?.customName ?? '',\n customTwicePerMonth: 'false',\n payPeriodPreviewRange: 0,\n }\n\n const { data: paySchedules } = usePaySchedulesGetAllSuspense({\n companyId,\n })\n\n const createPayScheduleMutation = usePaySchedulesCreateMutation()\n const updatePayScheduleMutation = usePaySchedulesUpdateMutation()\n\n const formMethods = useForm<PayScheduleInputs, unknown, PayScheduleOutputs>({\n resolver: zodResolver(PayScheduleSchema),\n defaultValues: transformedDefaultValues,\n })\n const { watch, setValue, reset, clearErrors, setError } = formMethods\n\n useEffect(() => {\n if (fieldErrors) {\n // TODO: These error messages are not being localized correctly\n fieldErrors.forEach(error => {\n setError(error.key as keyof PayScheduleInputs, { message: error.message })\n })\n }\n }, [setError, fieldErrors])\n\n const allValues = watch()\n\n const formattedAnchorPayDate = allValues.anchorPayDate\n ? formatDateToStringDate(allValues.anchorPayDate) || ''\n : ''\n const formattedAnchorEndOfPayPeriod = allValues.anchorEndOfPayPeriod\n ? formatDateToStringDate(allValues.anchorEndOfPayPeriod) || ''\n : ''\n\n const { data: payPreviewData, isLoading } = usePaySchedulesGetPreview(\n {\n companyId,\n frequency: allValues.frequency,\n anchorPayDate: formattedAnchorPayDate,\n anchorEndOfPayPeriod: formattedAnchorEndOfPayPeriod,\n day1: allValues.day1 ?? undefined,\n day2: allValues.day2 ?? undefined,\n },\n {\n enabled: Boolean(\n allValues.anchorPayDate &&\n allValues.anchorEndOfPayPeriod &&\n (mode === 'ADD_PAY_SCHEDULE' || mode === 'EDIT_PAY_SCHEDULE'),\n ),\n },\n )\n\n // Set the custom_twice_per_month value based on the frequency and day_1 and day_2 values as it is not set by the API call\n useEffect(() => {\n if (\n allValues.frequency === 'Twice per month' &&\n allValues.day1 === 15 &&\n allValues.day2 === 31 &&\n allValues.customTwicePerMonth === undefined\n ) {\n setValue('customTwicePerMonth', `1st15th`)\n } else if (\n allValues.frequency === 'Twice per month' &&\n allValues.customTwicePerMonth === undefined\n ) {\n setValue('customTwicePerMonth', `custom`)\n }\n }, [allValues.frequency, allValues.day1, allValues.day2, setValue, allValues.customTwicePerMonth])\n\n const handleAdd = () => {\n setMode('ADD_PAY_SCHEDULE')\n reset({})\n }\n const handleCancel = () => {\n setMode('LIST_PAY_SCHEDULES')\n reset({})\n clearErrors()\n setBaseError(null)\n }\n const handleEdit = (schedule: PayScheduleType) => {\n reset({\n frequency: schedule.frequency as Frequency,\n anchorPayDate: schedule.anchorPayDate ? new Date(schedule.anchorPayDate) : undefined,\n anchorEndOfPayPeriod: schedule.anchorEndOfPayPeriod\n ? new Date(schedule.anchorEndOfPayPeriod)\n : undefined,\n day1: schedule.day1 ?? undefined,\n day2: schedule.day2 ?? undefined,\n customName: schedule.customName ?? '',\n })\n setCurrentPaySchedule(schedule)\n setMode('EDIT_PAY_SCHEDULE')\n }\n const handleContinue = () => {\n onEvent(componentEvents.PAY_SCHEDULE_DONE)\n }\n const onSubmit: SubmitHandler<PayScheduleOutputs> = async data => {\n await baseSubmitHandler(data, async payload => {\n const formatPayloadDate = (date: Date | undefined): string => {\n return date ? formatDateToStringDate(date) || '' : ''\n }\n\n if (mode === 'ADD_PAY_SCHEDULE') {\n const createPayScheduleResponse = await createPayScheduleMutation.mutateAsync({\n request: {\n companyId,\n requestBody: {\n frequency: payload.frequency,\n anchorPayDate: formatPayloadDate(payload.anchorPayDate),\n anchorEndOfPayPeriod: formatPayloadDate(payload.anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1,\n day2: payload.day2,\n },\n },\n })\n onEvent(componentEvents.PAY_SCHEDULE_CREATED, createPayScheduleResponse)\n reset()\n } else if (mode === 'EDIT_PAY_SCHEDULE') {\n const version = currentPaySchedule?.version\n const updatePayScheduleResponse = await updatePayScheduleMutation.mutateAsync({\n request: {\n payScheduleId: currentPaySchedule?.uuid as string,\n companyId,\n requestBody: {\n frequency: payload.frequency,\n anchorPayDate: formatPayloadDate(payload.anchorPayDate),\n anchorEndOfPayPeriod: formatPayloadDate(payload.anchorEndOfPayPeriod),\n customName: payload.customName,\n day1: payload.day1,\n day2: payload.day2,\n version: version as string,\n },\n },\n })\n onEvent(componentEvents.PAY_SCHEDULE_UPDATED, updatePayScheduleResponse)\n reset()\n }\n setMode('LIST_PAY_SCHEDULES')\n })\n }\n\n return (\n <PayScheduleProvider\n value={{\n companyId,\n handleAdd,\n handleEdit,\n handleCancel,\n handleContinue,\n mode,\n paySchedules: paySchedules.payScheduleList,\n payPeriodPreview: payPreviewData?.object?.payPeriods,\n payPreviewLoading: isLoading,\n currentPaySchedule,\n }}\n >\n <span data-testid=\"pay-schedule-edit-form\">\n <FormProvider {...formMethods}>\n <Form onSubmit={formMethods.handleSubmit(onSubmit)}>\n {children ? (\n children\n ) : (\n <Flex flexDirection=\"column\">\n <Head />\n <List />\n <Edit />\n <Actions />\n </Flex>\n )}\n </Form>\n </FormProvider>\n </span>\n </PayScheduleProvider>\n )\n}\n\nPaySchedule.Head = Head\nPaySchedule.List = List\nPaySchedule.Edit = Edit\nPaySchedule.Actions = Actions\n"],"names":["PaySchedule","companyId","defaultValues","dictionary","props","useI18n","useComponentDictionary","jsx","BaseComponent","Root","children","baseSubmitHandler","onEvent","fieldErrors","setBaseError","useBase","mode","setMode","useState","currentPaySchedule","setCurrentPaySchedule","transformedDefaultValues","paySchedules","usePaySchedulesGetAllSuspense","createPayScheduleMutation","usePaySchedulesCreateMutation","updatePayScheduleMutation","usePaySchedulesUpdateMutation","formMethods","useForm","zodResolver","PayScheduleSchema","watch","setValue","reset","clearErrors","setError","useEffect","error","allValues","formattedAnchorPayDate","formatDateToStringDate","formattedAnchorEndOfPayPeriod","payPreviewData","isLoading","usePaySchedulesGetPreview","handleAdd","handleCancel","handleEdit","schedule","handleContinue","componentEvents","onSubmit","data","payload","formatPayloadDate","date","createPayScheduleResponse","version","updatePayScheduleResponse","PayScheduleProvider","FormProvider","Form","jsxs","Flex","Head","List","Edit","Actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+BO,MAAMA,IAAc,CAAC;AAAA,EAC1B,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACL,OACEC,GAAQ,qBAAqB,GAC7BC,GAAuB,uBAAuBH,CAAU,GAEtD,gBAAAI,EAACC,IAAe,EAAA,GAAGJ,GACjB,UAAA,gBAAAG,EAACE,MAAK,WAAAR,GAAsB,eAAAC,GACzB,UAAME,EAAA,SAAA,CACT,EACF,CAAA,IAIEK,KAAO,CAAC,EAAE,WAAAR,GAAW,UAAAS,GAAU,eAAAR,QAAsC;AACzE,QAAM,EAAE,mBAAAS,GAAmB,SAAAC,GAAS,aAAAC,GAAa,UAAUC,MAAiBC,GAAQ,GAC9E,CAACC,GAAMC,CAAO,IAAIC,EAAe,oBAAoB,GACrD,CAACC,GAAoBC,CAAqB,IAAIF,EAAiC,IAAI,GACnFG,IAA8C;AAAA,IAClD,WAAWnB,GAAe,aAAa;AAAA,IACvC,eAAeA,GAAe,gBAAgB,IAAI,KAA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UAAC,gBAAArB,EAAAuD,IAAA,EAAK,UAAUlC,EAAY,aAAawB,CAAQ,GAC9C,UAAA1C,KAGE,gBAAAqD,EAAAC,IAAA,EAAK,eAAc,UAClB,UAAA;AAAA,QAAA,gBAAAzD,EAAC0D,GAAK,EAAA;AAAA,0BACLC,GAAK,EAAA;AAAA,0BACLC,GAAK,EAAA;AAAA,0BACLC,GAAQ,CAAA,CAAA;AAAA,MAAA,GACX,EAAA,CAEJ,GACF,EACF,CAAA;AAAA,IAAA;AAAA,EACF;AAEJ;AAEApE,EAAY,OAAOiE;AACnBjE,EAAY,OAAOkE;AACnBlE,EAAY,OAAOmE;AACnBnE,EAAY,UAAUoE;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gusto/embedded-react-sdk",
3
- "version": "0.10.4",
3
+ "version": "0.10.5",
4
4
  "homepage": "https://github.com/Gusto/embedded-react-sdk",
5
5
  "bugs": {
6
6
  "url": "https://github.com/Gusto/embedded-react-sdk/issues"