@usebridge/sdk-react 0.3.0 → 0.4.1

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/dist/index.d.cts CHANGED
@@ -162,7 +162,7 @@ type FieldState<F extends Field, T = EligibilityInputState[F]["value"]> = {
162
162
  /**
163
163
  * Manages the input state for each field
164
164
  */
165
- declare function useEligibilityInputField<F extends Field, T = EligibilityInputState[F]["value"]>(field: F): FieldState<F, T>;
165
+ declare function useEligibilityInputField<F extends Field, T = EligibilityInputState[F]["value"]>(field: F, defaultValue?: T): FieldState<F, T>;
166
166
 
167
167
  /**
168
168
  * Aggregated determination of whether all inputs are valid
package/dist/index.d.ts CHANGED
@@ -162,7 +162,7 @@ type FieldState<F extends Field, T = EligibilityInputState[F]["value"]> = {
162
162
  /**
163
163
  * Manages the input state for each field
164
164
  */
165
- declare function useEligibilityInputField<F extends Field, T = EligibilityInputState[F]["value"]>(field: F): FieldState<F, T>;
165
+ declare function useEligibilityInputField<F extends Field, T = EligibilityInputState[F]["value"]>(field: F, defaultValue?: T): FieldState<F, T>;
166
166
 
167
167
  /**
168
168
  * Aggregated determination of whether all inputs are valid
package/dist/index.js CHANGED
@@ -1830,7 +1830,7 @@ import { createContext as createContext2 } from "react";
1830
1830
  var SoftEligibilityContext = createContext2(null);
1831
1831
 
1832
1832
  // src/eligibility-input/eligibility-input-provider.tsx
1833
- import { useContext as useContext5, useRef as useRef4 } from "react";
1833
+ import { useContext as useContext5, useRef as useRef5 } from "react";
1834
1834
  import "zustand";
1835
1835
 
1836
1836
  // src/eligibility-input/eligibility-input-store.ts
@@ -1933,14 +1933,14 @@ var useEligibilityInput = () => {
1933
1933
 
1934
1934
  // src/hard-eligibility/use-hard-eligibility-submit.ts
1935
1935
  import {
1936
- dateToDateObject,
1937
- HardEligibility as HardEligibility2
1936
+ HardEligibility as HardEligibility2,
1937
+ dateToDateObject
1938
1938
  } from "@usebridge/sdk-core";
1939
1939
 
1940
1940
  // src/eligibility-input/use-eligibility-input-field.ts
1941
- import { useContext as useContext4, useEffect as useEffect5, useMemo as useMemo3, useState as useState4 } from "react";
1941
+ import { useContext as useContext4, useEffect as useEffect5, useMemo as useMemo3, useRef as useRef4, useState as useState4, useLayoutEffect as useLayoutEffect2 } from "react";
1942
1942
  import { HardEligibility, SoftEligibility } from "@usebridge/sdk-core";
1943
- function useEligibilityInputField(field) {
1943
+ function useEligibilityInputField(field, defaultValue) {
1944
1944
  const input = useEligibilityInput();
1945
1945
  const inputField = input[field];
1946
1946
  const { requirePatient } = input;
@@ -2003,16 +2003,23 @@ function useEligibilityInputField(field) {
2003
2003
  default:
2004
2004
  throw new Error(`Unknown field: ${field}`);
2005
2005
  }
2006
+ const setValue = set;
2007
+ const hasSetDefaultValue = useRef4(false);
2008
+ useLayoutEffect2(() => {
2009
+ if (hasSetDefaultValue.current) return;
2010
+ if (defaultValue) setValue(defaultValue);
2011
+ hasSetDefaultValue.current = true;
2012
+ }, [setValue, defaultValue]);
2006
2013
  return useMemo3(
2007
2014
  () => ({
2008
2015
  value,
2009
- setValue: set,
2016
+ setValue,
2010
2017
  isVisible,
2011
2018
  isValid,
2012
2019
  isRequired,
2013
2020
  isDisabled
2014
2021
  }),
2015
- [value, set, isVisible, isValid, isRequired, isDisabled]
2022
+ [value, setValue, isVisible, isValid, isRequired, isDisabled]
2016
2023
  );
2017
2024
  }
2018
2025
 
@@ -2032,30 +2039,33 @@ function useEligibilityInputIsValid() {
2032
2039
  // src/hard-eligibility/use-hard-eligibility-submit.ts
2033
2040
  function useHardEligibilitySubmit() {
2034
2041
  const session = useHardEligibilitySession();
2035
- const { payer, state, firstName, lastName, memberId, dateOfBirth } = useEligibilityInput();
2036
- const { isVisible: isMemberIdVisible, isRequired: isMemberIdRequired } = useEligibilityInputField("memberId");
2042
+ const { state, payer, firstName, lastName, dateOfBirth, memberId } = useEligibilityInput();
2037
2043
  const { status } = useHardEligibilityState();
2038
- const inputIsValid = useEligibilityInputIsValid();
2044
+ const usesExistingPolicy = session.usesExistingPolicy;
2045
+ const inputIsValid = usesExistingPolicy ? Boolean(state.value) : useEligibilityInputIsValid();
2039
2046
  const isDisabled = !inputIsValid || !HardEligibility2.canSubmit(status);
2040
2047
  const submit = useCallback4(
2041
2048
  ({ clinicalInfo } = {}) => {
2042
- if (!payer.value) throw new Error("Payer is required");
2043
2049
  if (!state.value) throw new Error("State is required");
2044
- if (!firstName.value) throw new Error("First name is required");
2045
- if (!lastName.value) throw new Error("Last name is required");
2046
- if (!dateOfBirth.value) throw new Error("Date of birth is required");
2047
- if (isMemberIdRequired && !memberId.value) throw new Error("Member ID is required");
2048
- return session.submit({
2049
- payerId: payer.value.id,
2050
+ const submitArgs = {
2050
2051
  state: state.value,
2051
- firstName: firstName.value,
2052
- lastName: lastName.value,
2053
- memberId: isMemberIdVisible ? memberId.value : void 0,
2054
- dateOfBirth: dateToDateObject(dateOfBirth.value),
2055
2052
  clinicalInfo
2056
- });
2053
+ };
2054
+ if (!session.usesExistingPolicy) {
2055
+ if (!payer.value || !firstName.value || !lastName.value || !dateOfBirth.value) {
2056
+ throw new Error("Patient information is required");
2057
+ }
2058
+ submitArgs.patient = {
2059
+ payerId: payer.value.id,
2060
+ firstName: firstName.value.trim(),
2061
+ lastName: lastName.value.trim(),
2062
+ dateOfBirth: dateToDateObject(dateOfBirth.value),
2063
+ memberId: memberId.value?.trim() || void 0
2064
+ };
2065
+ }
2066
+ return session.submit(submitArgs);
2057
2067
  },
2058
- [session, payer, state, firstName, lastName, dateOfBirth, memberId]
2068
+ [session, state, payer, firstName, lastName, dateOfBirth, memberId]
2059
2069
  );
2060
2070
  return useMemo4(() => ({ isDisabled, submit }), [isDisabled, submit]);
2061
2071
  }
@@ -2063,7 +2073,7 @@ function useHardEligibilitySubmit() {
2063
2073
  // src/eligibility-input/eligibility-input-provider.tsx
2064
2074
  import { jsx as jsx2 } from "react/jsx-runtime";
2065
2075
  var EligibilityInputProvider = ({ children }) => {
2066
- const storeRef = useRef4(null);
2076
+ const storeRef = useRef5(null);
2067
2077
  const softEligibilityContext = useContext5(SoftEligibilityContext);
2068
2078
  const hardEligibilityContext = useContext5(HardEligibilityContext);
2069
2079
  if (!storeRef.current) {