Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: select component - part 4
Brad Barbin2d235602eb84
diff --git a/apps/carbon/app/components/Form/AccountCategory.tsx b/apps/carbon/app/components/Form/AccountCategory.tsxindex db20bc1ffa..eac9b87869 100644--- a/apps/carbon/app/components/Form/AccountCategory.tsx+++ b/apps/carbon/app/components/Form/AccountCategory.tsx@@ -1,38 +1,23 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,- useMount,-} from "@carbon/react";+import { useMount } from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";import type {AccountCategory as AccountCategoryType,getAccountCategoriesList,} from "~/modules/accounting";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";-type AccountCategorySelectProps = Omit<SelectProps, "options" | "onChange"> & {- onChange?: (accountCategory: AccountCategoryType | undefined) => void;-};+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";-const AccountCategory = ({- name,- label = "Account Category",- helperText,- isLoading,- isReadOnly,- placeholder = "Select Account Category",- onChange,- ...props-}: AccountCategorySelectProps) => {- const { getInputProps, error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);+type AccountCategorySelectProps = Omit<+ ComboboxProps,+ "options" | "onChange"+> & {+ onChange?: (accountCategory: AccountCategoryType | null) => void;+};+const AccountCategory = (props: AccountCategorySelectProps) => {const accountCategoryFetcher =useFetcher<Awaited<ReturnType<typeof getAccountCategoriesList>>>();@@ -40,68 +25,37 @@ const AccountCategory = ({accountCategoryFetcher.load(path.to.api.accountingCategories);});- const options = useMemo(() => {- return accountCategoryFetcher.data?.data?.map(- (c) =>- ({+ const options =+ useMemo(() => {+ return (+ accountCategoryFetcher.data?.data?.map((c) => ({value: c.id,label: c.category,- } ?? [])- );- }, [accountCategoryFetcher.data]);-- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);-- if (onChange && typeof onChange === "function") {- const categories = accountCategoryFetcher.data?.data ?? [];- if (!categories) {- onChange(undefined);- return;- }-- const category = categories?.find(- (category) => category.id === selection.value+ })) ?? []);+ }, [accountCategoryFetcher.data]) ?? [];- onChange(category as AccountCategoryType | undefined);- }- };+ const onChange = (+ selection: {+ value: string;+ label: string;+ } | null+ ) => {+ const category =+ accountCategoryFetcher.data?.data?.find(+ (category) => category.id === selection?.value+ ) ?? null;- const controlledValue = useMemo(- () => options?.find((option) => option.value === value),- [value, options]- );+ props.onChange?.(category as AccountCategoryType | null);+ };return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <ReactSelect- {...getInputProps({- // @ts-ignore- id: name,- })}- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- w="full"- isClearable- isReadOnly={isReadOnly}- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Account Category"}+ />);};diff --git a/apps/carbon/app/components/Form/AccountSubcategory.tsx b/apps/carbon/app/components/Form/AccountSubcategory.tsxindex cff958f756..681712a030 100644--- a/apps/carbon/app/components/Form/AccountSubcategory.tsx+++ b/apps/carbon/app/components/Form/AccountSubcategory.tsx@@ -1,57 +1,35 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useEffect, useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";import type {AccountSubcategory as AccountSubcategoryType,getAccountSubcategoriesByCategory,} from "~/modules/accounting";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";type AccountSubcategorySelectProps = Omit<- SelectProps,+ ComboboxProps,"options" | "onChange"> & {accountCategoryId?: string;- onChange?: (accountCategory: AccountSubcategoryType | undefined) => void;+ onChange?: (accountCategory: AccountSubcategoryType | null) => void;};-const AccountSubcategory = ({- name,- label = "Account Subcategory",- accountCategoryId,- helperText,- isReadOnly = false,- placeholder = "Select Account Subcategory",- onChange,-}: AccountSubcategorySelectProps) => {- const { error, getInputProps, defaultValue } = useField(name);-- const [accountSubcategory, setAccountSubcategory] = useControlField<{- value: string | number;- label: string;- } | null>(name);-+const AccountSubcategory = (props: AccountSubcategorySelectProps) => {const accountSubcategoriesFetcher =useFetcher<Awaited<ReturnType<typeof getAccountSubcategoriesByCategory>>>();useEffect(() => {- if (accountCategoryId) {+ if (props?.accountCategoryId) {accountSubcategoriesFetcher.load(- path.to.api.accountingSubcategories(accountCategoryId)+ path.to.api.accountingSubcategories(props.accountCategoryId));}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [accountCategoryId]);+ }, [props.accountCategoryId]);- const accountSubcategories = useMemo(+ const options = useMemo(() =>accountSubcategoriesFetcher.data?.data?.map((c) => ({value: c.id,@@ -61,56 +39,22 @@ const AccountSubcategory = ({[accountSubcategoriesFetcher.data]);- useEffect(() => {- // if the initial value is in the options, set it, otherwise set to null- if (accountSubcategories) {- setAccountSubcategory(- accountSubcategories.find((s) => s.value === defaultValue) ?? null- );-- if (onChange) {- const subcategory = accountSubcategoriesFetcher.data?.data?.find(- (c) => c.id === defaultValue- );+ const onChange = (newValue: { label: string; value: string } | null) => {+ const subCategory =+ accountSubcategoriesFetcher.data?.data?.find(+ (subCategory) => subCategory.id === newValue?.value+ ) ?? null;- onChange(subcategory);- }- }- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [accountSubcategories, defaultValue]);-- const handleChange = (newValue?: { label: string; value: string }) => {- setAccountSubcategory(newValue ?? null);- if (onChange) {- const subcategory = accountSubcategoriesFetcher.data?.data?.find(- (c) => c.id === newValue?.value- );-- onChange(subcategory);- }+ props.onChange?.(subCategory as AccountSubcategoryType | null);};return (- <FormControl isInvalid={!!error}>- <FormLabel htmlFor={name}>{label}</FormLabel>- <ReactSelect- {...getInputProps({- // @ts-ignore- id: name,- })}- placeholder={placeholder}- options={accountSubcategories}- value={accountSubcategory}- onChange={handleChange}- isReadOnly={isReadOnly}- w="full"- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Account Subcategory"}+ />);};diff --git a/apps/carbon/app/components/Form/CustomerContact.tsx b/apps/carbon/app/components/Form/CustomerContact.tsxindex 39b2e00e8e..18a5f5ac70 100644--- a/apps/carbon/app/components/Form/CustomerContact.tsx+++ b/apps/carbon/app/components/Form/CustomerContact.tsx@@ -1,116 +1,62 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo, useRef } from "react";-import { useControlField, useField } from "remix-validated-form";+import { useEffect, useMemo } from "react";import type {CustomerContact as CustomerContactType,getCustomerContacts,} from "~/modules/sales";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";-type CustomerContactSelectProps = Omit<SelectProps, "options" | "onChange"> & {+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type CustomerContactSelectProps = Omit<+ ComboboxProps,+ "options" | "onChange"+> & {customer?: string;- onChange?: (customerContact: CustomerContactType["contact"] | null) => void;+ onChange?: (customer: CustomerContactType | null) => void;};-const CustomerContact = ({- name,- label = "Customer Contact",- customer,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Customer Contact",- onChange,- ...props-}: CustomerContactSelectProps) => {- const initialLoad = useRef(true);- const { error } = useField(name);- const [value, setValue] = useControlField<string | null>(name);-- const customerContactFetcher =+const CustomerContact = (props: CustomerContactSelectProps) => {+ const customerContactsFetcher =useFetcher<Awaited<ReturnType<typeof getCustomerContacts>>>();useEffect(() => {- if (customer) {- customerContactFetcher.load(path.to.api.customerContacts(customer));- }-- if (initialLoad.current) {- initialLoad.current = false;- } else {- setValue(null);- if (onChange) {- onChange(null);- }+ if (props?.customer) {+ customerContactsFetcher.load(+ path.to.api.customerContacts(props.customer)+ );}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [customer]);+ }, [props.customer]);const options = useMemo(() =>- customerContactFetcher.data?.data- ? customerContactFetcher.data?.data.map((c) => ({- value: c.id,- // @ts-ignore- label: `${c.contact?.firstName} ${c.contact?.lastName}`,- }))- : [],- [customerContactFetcher.data]+ customerContactsFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: `${c.contact?.firstName} ${c.contact?.lastName}`,+ })) ?? [],++ [customerContactsFetcher.data]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = selection === null ? null : (selection.value as string);- setValue(newValue);- if (onChange && typeof onChange === "function") {- if (newValue === undefined) onChange(newValue);- const contact = customerContactFetcher.data?.data?.find(- (c) => c.id === newValue- );+ const onChange = (newValue: { label: string; value: string } | null) => {+ const contact =+ customerContactsFetcher.data?.data?.find(+ (contact) => contact.id === newValue?.value+ ) ?? null;- onChange(contact?.contact ?? null);- }+ props.onChange?.(contact as CustomerContactType | null);};- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value ?? ""} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- onChange={handleChange}- w="full"- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Customer Contact"}+ />);};-CustomerContact.displayName = "CustomerContact";-export default CustomerContact;diff --git a/apps/carbon/app/components/Form/CustomerLocation.tsx b/apps/carbon/app/components/Form/CustomerLocation.tsxindex 09425ece38..afd62408d9 100644--- a/apps/carbon/app/components/Form/CustomerLocation.tsx+++ b/apps/carbon/app/components/Form/CustomerLocation.tsx@@ -1,115 +1,62 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo, useRef } from "react";-import { useControlField, useField } from "remix-validated-form";+import { useEffect, useMemo } from "react";import type {CustomerLocation as CustomerLocationType,getCustomerLocations,} from "~/modules/sales";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";-type CustomerLocationSelectProps = Omit<SelectProps, "options" | "onChange"> & {+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type CustomerLocationSelectProps = Omit<+ ComboboxProps,+ "options" | "onChange"+> & {customer?: string;- onChange?: (customerLocation: CustomerLocationType | undefined) => void;+ onChange?: (customer: CustomerLocationType | null) => void;};-const CustomerLocation = ({- name,- label = "Customer Location",- customer,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Customer Location",- onChange,- ...props-}: CustomerLocationSelectProps) => {- const initialLoad = useRef(true);- const { error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);-- const customerLocationFetcher =+const CustomerLocation = (props: CustomerLocationSelectProps) => {+ const customerLocationsFetcher =useFetcher<Awaited<ReturnType<typeof getCustomerLocations>>>();useEffect(() => {- if (customer) {- customerLocationFetcher.load(path.to.api.customerLocations(customer));- }- if (initialLoad.current) {- initialLoad.current = false;- } else {- setValue(undefined);- if (onChange) {- onChange(undefined);- }+ if (props?.customer) {+ customerLocationsFetcher.load(+ path.to.api.customerLocations(props.customer)+ );}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [customer]);+ }, [props.customer]);const options = useMemo(() =>- customerLocationFetcher.data?.data- ? customerLocationFetcher.data?.data.map((c) => ({- value: c.id,- // @ts-ignore- label: `${c.address?.addressLine1} ${c.address?.city}, ${c.address?.state}`,- }))- : [],- [customerLocationFetcher.data]+ customerLocationsFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: `${c.address?.addressLine1} ${c.address?.city}, ${c.address?.state}`,+ })) ?? [],++ [customerLocationsFetcher.data]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);- if (onChange && typeof onChange === "function") {- if (newValue === undefined) onChange(newValue);- const contact = customerLocationFetcher.data?.data?.find(- (c) => c.id === newValue- );+ const onChange = (newValue: { label: string; value: string } | null) => {+ const location =+ customerLocationsFetcher.data?.data?.find(+ (location) => location.id === newValue?.value+ ) ?? null;- onChange(contact);- }+ props.onChange?.(location as CustomerLocationType | null);};- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- onChange={handleChange}- w="full"- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Customer Location"}+ />);};-CustomerLocation.displayName = "CustomerLocation";-export default CustomerLocation;diff --git a/apps/carbon/app/components/Form/Department.tsx b/apps/carbon/app/components/Form/Department.tsxindex 52057cb452..ff501adbe1 100644--- a/apps/carbon/app/components/Form/Department.tsx+++ b/apps/carbon/app/components/Form/Department.tsx@@ -1,33 +1,14 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,- useMount,-} from "@carbon/react";+import { useMount } from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";import type { getDepartmentsList } from "~/modules/resources";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";-type DepartmentSelectProps = Omit<SelectProps, "options">;--const Department = ({- name,- label = "Department",- helperText,- isLoading,- isReadOnly,- placeholder = "Select Department",- onChange,- ...props-}: DepartmentSelectProps) => {- const { error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);+type DepartmentSelectProps = Omit<ComboboxProps, "options">;+const Department = (props: DepartmentSelectProps) => {const departmentFetcher =useFetcher<Awaited<ReturnType<typeof getDepartmentsList>>>();@@ -46,42 +27,12 @@ const Department = ({[departmentFetcher.data]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);- if (onChange && typeof onChange === "function") {- onChange(selection);- }- };-- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ label={props?.label ?? "Department"}+ />);};diff --git a/apps/carbon/app/components/Form/Location.tsx b/apps/carbon/app/components/Form/Location.tsxindex af6d42992f..a6355cbe0d 100644--- a/apps/carbon/app/components/Form/Location.tsx+++ b/apps/carbon/app/components/Form/Location.tsx@@ -1,43 +1,16 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,- useMount,-} from "@carbon/react";+import { useMount } from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";-import type { getLocations } from "~/modules/resources";+import type { getLocationsList } from "~/modules/resources";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";-type LocationSelectProps = Omit<SelectProps, "options" | "onChange"> & {- isClearable?: boolean;- onChange?: (- selected: {- value: string | number;- label: string;- } | null- ) => void;-};--const Location = ({- name,- label = "Location",- helperText,- isLoading,- isClearable,- placeholder = "Select Location",- onChange,- ...props-}: LocationSelectProps) => {- const { error } = useField(name);- const [value, setValue] = useControlField<string | null>(name);+type LocationSelectProps = Omit<ComboboxProps, "options">;+const Location = (props: LocationSelectProps) => {const locationFetcher =- useFetcher<Awaited<ReturnType<typeof getLocations>>>();+ useFetcher<Awaited<ReturnType<typeof getLocationsList>>>();useMount(() => {locationFetcher.load(path.to.api.locations);@@ -54,42 +27,8 @@ const Location = ({[locationFetcher.data]);- const handleChange = (- selection: {- value: string | number;- label: string;- } | null- ) => {- const newValue = (selection?.value as string) ?? null;- setValue(newValue);- onChange?.(selection);- };-- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value ?? ""} />- <ReactSelect- {...props}- value={controlledValue}- isClearable={isClearable}- isLoading={isLoading}- options={options}- placeholder={placeholder}- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox options={options} {...props} label={props?.label ?? "Location"} />);};diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsxindex a1e7b3593e..8801ab1e73 100644--- a/apps/carbon/app/components/Form/Part.tsx+++ b/apps/carbon/app/components/Form/Part.tsx@@ -1,33 +1,14 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";import type { PartReplenishmentSystem } from "~/modules/parts";import { useParts } from "~/stores";-import type { SelectProps } from "./Select";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";-type PartSelectProps = Omit<SelectProps, "options"> & {+type PartSelectProps = Omit<ComboboxProps, "options"> & {partReplenishmentSystem?: PartReplenishmentSystem;};-const Part = ({- name,- label = "Part",- partReplenishmentSystem,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Part",- onChange,- ...props-}: PartSelectProps) => {- const { getInputProps, error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);+const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {const [parts] = useParts();const options = useMemo(@@ -49,46 +30,8 @@ const Part = ({[partReplenishmentSystem, parts]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);- if (onChange && typeof onChange === "function") {- onChange(selection);- }- };-- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <ReactSelect- {...getInputProps({- // @ts-ignore- id: name,- })}- {...props}- options={options}- value={controlledValue}- isLoading={isLoading}- placeholder={placeholder}- w="full"- isReadOnly={isReadOnly}- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox options={options} {...props} label={props?.label ?? "Part"} />);};diff --git a/apps/carbon/app/components/Form/SelectControlled.tsx b/apps/carbon/app/components/Form/SelectControlled.tsxindex 0caa7522a1..ff05780b88 100644--- a/apps/carbon/app/components/Form/SelectControlled.tsx+++ b/apps/carbon/app/components/Form/SelectControlled.tsx@@ -3,79 +3,67 @@ import {FormErrorMessage,FormHelperText,FormLabel,- ReactSelect,} from "@carbon/react";import { useEffect } from "react";+import { useControlField, useField } from "remix-validated-form";+import { Combobox as ComboboxBase } from "~/components";+import type { ComboboxProps as ComboboxBaseProps } from "~/components/Combobox";-export type SelectControlledProps = {+export type ComboboxProps = Omit<ComboboxBaseProps, "onChange"> & {name: string;label?: string;- options: { value: string | number; label: string }[];helperText?: string;- isReadOnly?: boolean;- isLoading?: boolean;- placeholder?: string;- value: string | undefined;- onChange?: (newValue: string | number | undefined) => void;+ options: { value: string | number; label: string }[];+ onChange?: (newValue: { value: string; label: string } | null) => void;};const SelectControlled = ({name,label,- options,helperText,- isLoading,- isReadOnly,- placeholder,- value,- onChange,+ options,...props-}: SelectControlledProps) => {+}: ComboboxProps) => {const { getInputProps, error } = useField(name);- const [controlValue, setControlValue] = useControlField(name);+ const [controlValue, setControlValue] = useControlField<string | undefined>(+ name+ );useEffect(() => {- setControlValue(value);- }, [setControlValue, value]);+ setControlValue(props.value ?? "");+ }, [props.value, setControlValue]);- const handleChange = (- selection: { value: string | number; label: string } | undefined- ) => {- setControlValue(selection?.value || undefined);- if (onChange && typeof onChange === "function") {- onChange(selection?.value);+ const onChange = (value: string) => {+ if (value) {+ props?.onChange?.(options.find((o) => o.value === value) ?? null);+ } else {+ props?.onChange?.(null);}};return (<FormControl isInvalid={!!error}>{label && <FormLabel htmlFor={name}>{label}</FormLabel>}- {options.length > 0 ? (- <ReactSelect- {...getInputProps({- // @ts-ignore- id: name,- })}- {...props}- // @ts-ignore- isReadOnly={isReadOnly}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- w="full"- value={options.find((option) => option.value === controlValue)}- onChange={handleChange}- />- ) : (- <ReactSelect- isLoading={isLoading}- options={[]}- // @ts-ignore- w="full"- />- )}+ <input+ {...getInputProps({+ id: name,+ })}+ type="hidden"+ name={name}+ id={name}+ value={controlValue}+ />+ <ComboboxBase+ {...props}+ options={options}+ value={controlValue}+ onChange={(newValue) => {+ setControlValue(newValue ?? "");+ onChange(newValue ?? "");+ }}+ className="w-full"+ />{error ? (<FormErrorMessage>{error}</FormErrorMessage>diff --git a/apps/carbon/app/components/Form/Sequence.tsx b/apps/carbon/app/components/Form/Sequence.tsxindex 9340faad4b..8fd8828496 100644--- a/apps/carbon/app/components/Form/Sequence.tsx+++ b/apps/carbon/app/components/Form/Sequence.tsx@@ -1,41 +1,22 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,- useMount,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";-import type { getSequencesList } from "~/modules/settings";import { path } from "~/utils/path";++import { useMount } from "@carbon/react";+import type { getSequencesList } from "~/modules/settings";import type { SelectProps } from "./Select";+import Select from "./Select";type SequenceSelectProps = Omit<SelectProps, "options"> & {table: string;};-const Sequence = ({- name,- label = "Sequence",- table,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Sequence",- onChange,- ...props-}: SequenceSelectProps) => {- const { error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);-+const Sequence = (props: SequenceSelectProps) => {const sequenceFetcher =useFetcher<Awaited<ReturnType<typeof getSequencesList>>>();useMount(() => {- sequenceFetcher.load(path.to.api.sequences(table));+ sequenceFetcher.load(path.to.api.sequences(props.table));});const options = useMemo(@@ -49,45 +30,9 @@ const Sequence = ({[sequenceFetcher.data]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);- if (onChange && typeof onChange === "function") {- onChange(selection);- }- };-- const controlledValue = useMemo(- () =>- options.find((option) => option.value === value) ?? options?.[0] ?? null,- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Select options={options} {...props} label={props?.label ?? "Sequence"} />);};-Sequence.displayName = "Sequence";-export default Sequence;diff --git a/apps/carbon/app/components/Form/Service.tsx b/apps/carbon/app/components/Form/Service.tsxindex 92bd0e870f..2caab9e053 100644--- a/apps/carbon/app/components/Form/Service.tsx+++ b/apps/carbon/app/components/Form/Service.tsx@@ -1,36 +1,16 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,- useMount,-} from "@carbon/react";+import { useMount } from "@carbon/react";import { useFetcher } from "@remix-run/react";import { useMemo } from "react";-import { useControlField, useField } from "remix-validated-form";import type { ServiceType, getServicesList } from "~/modules/parts";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";-type ServiceSelectProps = Omit<SelectProps, "options"> & {+type ServiceSelectProps = Omit<ComboboxProps, "options"> & {serviceType?: ServiceType;};-const Service = ({- name,- label = "Service",- serviceType,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Service",- onChange,- ...props-}: ServiceSelectProps) => {- const { getInputProps, error } = useField(name);- const [value, setValue] = useControlField<string | undefined>(name);-+const Service = ({ serviceType, ...props }: ServiceSelectProps) => {const servicesFetcher =useFetcher<Awaited<ReturnType<typeof getServicesList>>>();@@ -50,46 +30,8 @@ const Service = ({[servicesFetcher.data]);- const handleChange = (selection: {- value: string | number;- label: string;- }) => {- const newValue = (selection.value as string) || undefined;- setValue(newValue);- if (onChange && typeof onChange === "function") {- onChange(selection);- }- };-- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <ReactSelect- {...getInputProps({- // @ts-ignore- id: name,- })}- {...props}- options={options}- value={controlledValue}- isLoading={isLoading}- placeholder={placeholder}- w="full"- isReadOnly={isReadOnly}- onChange={handleChange}- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox options={options} {...props} label={props?.label ?? "Service"} />);};diff --git a/apps/carbon/app/components/Form/Shift.tsx b/apps/carbon/app/components/Form/Shift.tsxnew file mode 100644index 0000000000..bc10a68425--- /dev/null+++ b/apps/carbon/app/components/Form/Shift.tsx@@ -0,0 +1,38 @@+import { useFetcher } from "@remix-run/react";+import { useEffect, useMemo } from "react";+import { path } from "~/utils/path";++import type { getShiftsList } from "~/modules/resources";+import type { SelectProps } from "./Select";+import Select from "./Select";++type ShiftSelectProps = Omit<SelectProps, "options"> & {+ location?: string;+};++const Shift = (props: ShiftSelectProps) => {+ const shiftFetcher = useFetcher<Awaited<ReturnType<typeof getShiftsList>>>();++ useEffect(() => {+ if (props?.location) {+ shiftFetcher.load(path.to.api.shifts(props.location));+ }+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [props.location]);++ const options = useMemo(+ () =>+ shiftFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: c.name,+ })) ?? [],++ [shiftFetcher.data]+ );++ return (+ <Select options={options} {...props} label={props?.label ?? "Shift"} />+ );+};++export default Shift;diff --git a/apps/carbon/app/components/Form/SupplierContact.tsx b/apps/carbon/app/components/Form/SupplierContact.tsxindex f57b2459a1..891ae6120e 100644--- a/apps/carbon/app/components/Form/SupplierContact.tsx+++ b/apps/carbon/app/components/Form/SupplierContact.tsx@@ -1,119 +1,62 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo, useRef } from "react";-import { useControlField, useField } from "remix-validated-form";+import { useEffect, useMemo } from "react";import type {SupplierContact as SupplierContactType,getSupplierContacts,} from "~/modules/purchasing";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";-type SupplierContactSelectProps = Omit<SelectProps, "options" | "onChange"> & {+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type SupplierContactSelectProps = Omit<+ ComboboxProps,+ "options" | "onChange"+> & {supplier?: string;- onChange?: (supplierContact: SupplierContactType["contact"] | null) => void;+ onChange?: (supplier: SupplierContactType | null) => void;};-const SupplierContact = ({- name,- label = "Supplier Contact",- supplier,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Supplier Contact",- onChange,- ...props-}: SupplierContactSelectProps) => {- const initialLoad = useRef(true);- const { error } = useField(name);- const [value, setValue] = useControlField<string | null>(name);-- const supplierContactFetcher =+const SupplierContact = (props: SupplierContactSelectProps) => {+ const supplierContactsFetcher =useFetcher<Awaited<ReturnType<typeof getSupplierContacts>>>();useEffect(() => {- if (supplier) {- supplierContactFetcher.load(path.to.api.supplierContacts(supplier));- }-- if (initialLoad.current) {- initialLoad.current = false;- } else {- setValue(null);- if (onChange) {- onChange(null);- }+ if (props?.supplier) {+ supplierContactsFetcher.load(+ path.to.api.supplierContacts(props.supplier)+ );}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [supplier]);+ }, [props.supplier]);const options = useMemo(() =>- supplierContactFetcher.data?.data- ? supplierContactFetcher.data?.data.map((c) => ({- value: c.id,- // @ts-ignore- label: `${c.contact?.firstName} ${c.contact?.lastName}`,- }))- : [],- [supplierContactFetcher.data]+ supplierContactsFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: `${c.contact?.firstName} ${c.contact?.lastName}`,+ })) ?? [],++ [supplierContactsFetcher.data]);- const handleChange = (- selection: {- value: string | number;- label: string;- } | null- ) => {- const newValue = selection === null ? null : (selection.value as string);- setValue(newValue);- if (onChange && typeof onChange === "function") {- if (newValue === null) onChange(newValue);- const contact = supplierContactFetcher.data?.data?.find(- (c) => c.id === newValue- );+ const onChange = (newValue: { label: string; value: string } | null) => {+ const contact =+ supplierContactsFetcher.data?.data?.find(+ (contact) => contact.id === newValue?.value+ ) ?? null;- onChange(contact?.contact ?? null);- }+ props.onChange?.(contact as SupplierContactType | null);};- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value ?? ""} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- // @ts-ignore- onChange={handleChange}- isClearable- w="full"- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Supplier Contact"}+ />);};-SupplierContact.displayName = "SupplierContact";-export default SupplierContact;diff --git a/apps/carbon/app/components/Form/SupplierLocation.tsx b/apps/carbon/app/components/Form/SupplierLocation.tsxindex 1efe5c567d..a7b8312710 100644--- a/apps/carbon/app/components/Form/SupplierLocation.tsx+++ b/apps/carbon/app/components/Form/SupplierLocation.tsx@@ -1,118 +1,62 @@-import {- FormControl,- FormErrorMessage,- FormHelperText,- FormLabel,- ReactSelect,-} from "@carbon/react";import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo, useRef } from "react";-import { useControlField, useField } from "remix-validated-form";+import { useEffect, useMemo } from "react";import type {SupplierLocation as SupplierLocationType,getSupplierLocations,} from "~/modules/purchasing";import { path } from "~/utils/path";-import type { SelectProps } from "./Select";-type SupplierLocationSelectProps = Omit<SelectProps, "options" | "onChange"> & {+import type { ComboboxProps } from "./Combobox";+import Combobox from "./Combobox";++type SupplierLocationSelectProps = Omit<+ ComboboxProps,+ "options" | "onChange"+> & {supplier?: string;- onChange?: (supplierLocation: SupplierLocationType | null) => void;+ onChange?: (supplier: SupplierLocationType | null) => void;};-const SupplierLocation = ({- name,- label = "Supplier Location",- supplier,- helperText,- isLoading,- isReadOnly,- placeholder = "Select Supplier Location",- onChange,- ...props-}: SupplierLocationSelectProps) => {- const initialLoad = useRef(true);- const { error } = useField(name);- const [value, setValue] = useControlField<string | null>(name);-- const supplierLocationFetcher =+const SupplierLocation = (props: SupplierLocationSelectProps) => {+ const supplierLocationsFetcher =useFetcher<Awaited<ReturnType<typeof getSupplierLocations>>>();useEffect(() => {- if (supplier) {- supplierLocationFetcher.load(path.to.api.supplierLocations(supplier));- }- if (initialLoad.current) {- initialLoad.current = false;- } else {- setValue(null);- if (onChange) {- onChange(null);- }+ if (props?.supplier) {+ supplierLocationsFetcher.load(+ path.to.api.supplierLocations(props.supplier)+ );}// eslint-disable-next-line react-hooks/exhaustive-deps- }, [supplier]);+ }, [props.supplier]);const options = useMemo(() =>- supplierLocationFetcher.data?.data- ? supplierLocationFetcher.data?.data.map((c) => ({- value: c.id,- // @ts-ignore- label: `${c.address?.addressLine1} ${c.address?.city}, ${c.address?.state}`,- }))- : [],- [supplierLocationFetcher.data]+ supplierLocationsFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: `${c.address?.addressLine1} ${c.address?.city}, ${c.address?.state}`,+ })) ?? [],++ [supplierLocationsFetcher.data]);- const handleChange = (- selection: {- value: string | number;- label: string;- } | null- ) => {- const newValue = (selection?.value as string) ?? null;- setValue(newValue);- if (onChange && typeof onChange === "function") {- if (newValue === null) onChange(newValue);- const location = supplierLocationFetcher.data?.data?.find(- (c) => c.id === newValue- );+ const onChange = (newValue: { label: string; value: string } | null) => {+ const location =+ supplierLocationsFetcher.data?.data?.find(+ (location) => location.id === newValue?.value+ ) ?? null;- onChange(location ?? null);- }+ props.onChange?.(location as SupplierLocationType | null);};- const controlledValue = useMemo(- // @ts-ignore- () => options.find((option) => option.value === value),- [value, options]- );-return (- <FormControl isInvalid={!!error}>- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}- <input type="hidden" name={name} id={name} value={value ?? ""} />- <ReactSelect- {...props}- value={controlledValue}- isLoading={isLoading}- options={options}- placeholder={placeholder}- isClearable- // @ts-ignore- onChange={handleChange}- w="full"- />- {error ? (- <FormErrorMessage>{error}</FormErrorMessage>- ) : (- helperText && <FormHelperText>{helperText}</FormHelperText>- )}- </FormControl>+ <Combobox+ options={options}+ {...props}+ onChange={onChange}+ label={props?.label ?? "Supplier Location"}+ />);};-SupplierLocation.displayName = "SupplierLocation";-export default SupplierLocation;diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.tsindex 38d5dd1fa4..c382036782 100644--- a/apps/carbon/app/components/Form/index.ts+++ b/apps/carbon/app/components/Form/index.ts@@ -31,6 +31,7 @@ import Select from "./Select";import SelectControlled from "./SelectControlled";import Sequence from "./Sequence";import Service from "./Service";+import Shift from "./Shift";import Slider from "./Slider";import Submit from "./Submit";import Supplier from "./Supplier";@@ -76,6 +77,7 @@ export {SelectControlled,Sequence,Service,+ Shift,Slider,Submit,Supplier,diff --git a/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx b/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsxindex 00031bc0b1..8c3f0c4f30 100644--- a/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx+++ b/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx@@ -10,7 +10,7 @@* @see WAI-ARIA Tree View https://www.w3.org/WAI/ARIA/apg/patterns/treeview/*/-import { FormLabel, ReactSelect } from "@carbon/react";+import { FormLabel } from "@carbon/react";import { usePermissions } from "~/hooks";import Combobox from "./components/Combobox";import Container from "./components/Container";@@ -25,8 +25,7 @@ import useUserSelect from "./useUserSelect";export default function Component(props: UserSelectProps) {const permissions = usePermissions();- if (!permissions.is("employee"))- return <ReactSelect options={[]} isDisabled placeholder="Select..." />;+ if (!permissions.is("employee")) return null;return <UserSelect {...props} />;}diff --git a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsxindex 6006b5431a..aa91ce0f74 100644--- a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx+++ b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx@@ -59,7 +59,7 @@ const Input = () => {/><InputRightElement>- <HStack spacing={1} className="mr-2">+ <HStack spacing={1}>{loading && <Spinner size="sm" />}{!loading && !disabled && inputValue.length > 0 && (<IconButtondiff --git a/apps/carbon/app/components/Selectors/UserSelect/components/TreeSelect.tsx b/apps/carbon/app/components/Selectors/UserSelect/components/TreeSelect.tsxindex af8ddc25eb..c1e0ce1b30 100644--- a/apps/carbon/app/components/Selectors/UserSelect/components/TreeSelect.tsx+++ b/apps/carbon/app/components/Selectors/UserSelect/components/TreeSelect.tsx@@ -1,7 +1,7 @@-import { HStack, Loading } from "@carbon/react";-import type { IconProps } from "@chakra-ui/react";+import { HStack, Loading, cn } from "@carbon/react";import { Box, Icon, List, ListItem } from "@chakra-ui/react";-import { FaCheck, FaChevronRight } from "react-icons/fa";+import { FaChevronRight } from "react-icons/fa";+import { RxCheck } from "react-icons/rx";import useUserSelectContext from "../provider";import type { IndividualOrGroup, OptionGroup } from "../types";import { useGroupStyles, useOptionStyles } from "./useUserSelectStyles";@@ -76,6 +76,7 @@ const Group = ({ group }: { group: OptionGroup }) => {><Boxrole="treeitem"+ aria-selected={isExpanded ? "true" : "false"}onClick={() =>group.expanded ? onGroupCollapse(group.uid) : onGroupExpand(group.uid)}@@ -113,10 +114,6 @@ const Group = ({ group }: { group: OptionGroup }) => {);};-const CheckIcon = (iconProps: IconProps) => (- <Icon as={FaCheck} {...iconProps} />-);-const Option = ({id,item,@@ -147,13 +144,11 @@ const Option = ({sx={sx}><HStack spacing={1} className="w-full items-center">- <CheckIcon- display="block"- marginEnd="0.75rem"- fontSize="0.8rem"- w={4}- h={4}- opacity={isSelected ? 1 : 0}+ <RxCheck+ className={cn(+ "block mr-[0.75rem] text-[0.8rem] w-4 h-4",+ isSelected ? "opacity-100" : "opacity-0"+ )}/><span className="line-clamp-1">{name}</span></HStack>diff --git a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountForm/ChartOfAccountForm.tsx b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountForm/ChartOfAccountForm.tsxindex a2ad858e40..bbe470e893 100644--- a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountForm/ChartOfAccountForm.tsx+++ b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountForm/ChartOfAccountForm.tsx@@ -65,7 +65,7 @@ const ChartOfAccountForm = ({ initialValues }: ChartOfAccountFormProps) => {? !permissions.can("update", "accounting"): !permissions.can("create", "accounting");- const onAccountCategoryChange = (category?: AccountCategoryType) => {+ const onAccountCategoryChange = (category: AccountCategoryType | null) => {if (category) {setAccountCategoryId(category.id ?? "");setIncomeBalance(category.incomeBalance ?? "Income Statement");@@ -140,7 +140,7 @@ const ChartOfAccountForm = ({ initialValues }: ChartOfAccountFormProps) => {value={incomeBalance}onChange={(newValue) => {if (newValue)- setIncomeBalance(newValue as AccountIncomeBalance);+ setIncomeBalance(newValue.value as AccountIncomeBalance);}}/></VStack>@@ -154,7 +154,8 @@ const ChartOfAccountForm = ({ initialValues }: ChartOfAccountFormProps) => {}))}value={accountClass}onChange={(newValue) => {- if (newValue) setAccountClass(newValue as AccountClass);+ if (newValue)+ setAccountClass(newValue.value as AccountClass);}}/><Selectdiff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsxindex 76aa5a084f..21d63bd030 100644--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx@@ -138,9 +138,9 @@ const ReceiptForm = ({})) ?? []}value={locationId ?? undefined}- onChange={(newValue) =>- setLocationId(newValue as string)- }+ onChange={(newValue) => {+ if (newValue) setLocationId(newValue.value as string);+ }}isReadOnly={isPosted}/><Select@@ -151,10 +151,12 @@ const ReceiptForm = ({value: v,}))}onChange={(newValue) => {- setSourceDocument(- newValue.value as ReceiptSourceDocument- );- setSourceDocumentId(null);+ if (newValue) {+ setSourceDocument(+ newValue.value as ReceiptSourceDocument+ );+ setSourceDocumentId(null);+ }}}isReadOnly={isPosted}/>@@ -167,7 +169,9 @@ const ReceiptForm = ({}))}value={sourceDocumentId ?? undefined}onChange={(newValue) => {- setSourceDocumentId(newValue as string);+ if (newValue) {+ setSourceDocumentId(newValue.value as string);+ }}}isReadOnly={isPosted}/>diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters/ReceiptsTableFilters.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters/ReceiptsTableFilters.tsxindex 63bc047ea7..7c12de78fc 100644--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters/ReceiptsTableFilters.tsx+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters/ReceiptsTableFilters.tsx@@ -1,10 +1,10 @@-import { Button, HStack, useMount } from "@carbon/react";+import { Button, HStack } from "@carbon/react";import { Link } from "@remix-run/react";import { IoMdAdd } from "react-icons/io";import { Combobox } from "~/components";import { TableFilters } from "~/components/Layout";import { DebouncedInput } from "~/components/Search";-import { usePermissions, useUrlParams, useUser } from "~/hooks";+import { usePermissions, useUrlParams } from "~/hooks";import { receiptSourceDocumentType } from "~/modules/inventory";import type { ListItem } from "~/types";@@ -15,15 +15,6 @@ type ReceiptsTableFiltersProps = {const ReceiptsTableFilters = ({ locations }: ReceiptsTableFiltersProps) => {const [params, setParams] = useUrlParams();const permissions = usePermissions();- const {- defaults: { locationId },- } = useUser();-- useMount(() => {- if (!params.get("location") && locationId) {- setParams({ location: locationId });- }- });const sourceDocumentOptions = receiptSourceDocumentType.map((type) => ({label: type,diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm/PurchaseInvoiceForm.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm/PurchaseInvoiceForm.tsxindex 9443ae000c..8cf9642e7a 100644--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm/PurchaseInvoiceForm.tsx+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceForm/PurchaseInvoiceForm.tsx@@ -16,7 +16,6 @@ import {Hidden,Input,Select,- SelectControlled,Submit,Supplier,SupplierContact,@@ -126,7 +125,7 @@ const PurchaseInvoiceForm = ({<DatePicker name="dateIssued" label="Date Issued" /><DatePicker name="dateDue" label="Due Date" />{isEditing && (- <SelectControlled+ <Selectname="status"label="Status"value={initialValues.status}diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsxindex 41f53c509f..d938f0873d 100644--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx@@ -185,20 +185,18 @@ const PurchaseInvoiceLineForm = ({});};- const onLocationChange = async (- newLocationId: string | number | undefined- ) => {+ const onLocationChange = async (newLocation: { value: string } | null) => {if (!supabase) throw new Error("supabase is not defined");- if (typeof newLocationId !== "string")+ if (typeof newLocation?.value !== "string")throw new Error("locationId is not a string");- setLocationId(newLocationId);+ setLocationId(newLocation.value);if (!partData.partId) return;const shelf = await supabase.from("partInventory").select("defaultShelfId").eq("partId", partData.partId)- .eq("locationId", newLocationId)+ .eq("locationId", newLocation.value).maybeSingle();setPartData((d) => ({@@ -335,12 +333,14 @@ const PurchaseInvoiceLineForm = ({label="Shelf"options={shelfOptions}value={partData.shelfId}- onChange={(newValue) =>- setPartData((d) => ({- ...d,- shelfId: newValue as string,- }))- }+ onChange={(newValue) => {+ if (newValue) {+ setPartData((d) => ({+ ...d,+ shelfId: newValue.value,+ }));+ }+ }}/>)}</>diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm/PurchaseOrderForm.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm/PurchaseOrderForm.tsxindex ad91823612..d142aa8b02 100644--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm/PurchaseOrderForm.tsx+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm/PurchaseOrderForm.tsx@@ -15,7 +15,6 @@ import {Hidden,Input,Select,- SelectControlled,Submit,Supplier,SupplierContact,@@ -124,7 +123,7 @@ const PurchaseOrderForm = ({ initialValues }: PurchaseOrderFormProps) => {{isEditing && (<>{permissions.can("delete", "purchasing") && (- <SelectControlled+ <Selectname="status"label="Status"value={initialValues.status}diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsxindex 28e266d8ef..38ddafac75 100644--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx@@ -183,20 +183,18 @@ const PurchaseOrderLineForm = ({});};- const onLocationChange = async (- newLocationId: string | number | undefined- ) => {+ const onLocationChange = async (newLocation: { value: string } | null) => {if (!supabase) throw new Error("supabase is not defined");- if (typeof newLocationId !== "string")+ if (typeof newLocation?.value !== "string")throw new Error("locationId is not a string");- setLocationId(newLocationId);+ setLocationId(newLocation.value);if (!partData.partId) return;const shelf = await supabase.from("partInventory").select("defaultShelfId").eq("partId", partData.partId)- .eq("locationId", newLocationId)+ .eq("locationId", newLocation.value).maybeSingle();setPartData((d) => ({@@ -333,12 +331,14 @@ const PurchaseOrderLineForm = ({label="Shelf"options={shelfOptions}value={partData.shelfId}- onChange={(newValue) =>- setPartData((d) => ({- ...d,- shelfId: newValue as string,- }))- }+ onChange={(newValue) => {+ if (newValue) {+ setPartData((d) => ({+ ...d,+ shelfId: newValue?.value as string,+ }));+ }+ }}/>)}</>diff --git a/apps/carbon/app/modules/resources/resources.models.ts b/apps/carbon/app/modules/resources/resources.models.tsindex 26286020c0..7435c44efd 100644--- a/apps/carbon/app/modules/resources/resources.models.ts+++ b/apps/carbon/app/modules/resources/resources.models.ts@@ -174,13 +174,11 @@ export const locationValidator = withZod(export const partnerValidator = withZod(z.object({id: z.string().min(20, { message: "Supplier Location is required" }),- supplierId: z.string().min(20, { message: "Supplier is required" }),+ supplierId: zfd.text(z.string().optional()),hoursPerWeek: zfd.numeric(z.number().min(0, { message: "Hours are required" })),- abilities: z- .array(z.string().min(20, { message: "Invalid ability" }))- .min(1, { message: "An ability is required" }),+ abilityId: z.string().min(20, { message: "Invalid ability" }),}));diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.tsindex 836db4a758..2eec45ecfd 100644--- a/apps/carbon/app/modules/resources/resources.service.ts+++ b/apps/carbon/app/modules/resources/resources.service.ts@@ -10,6 +10,7 @@ import type {employeeJobValidator,equipmentValidator,locationValidator,+ partnerValidator,} from "./resources.models";export async function deleteAbility(@@ -287,7 +288,7 @@ export async function getContractors(}if (args?.ability) {- query.contains("abilityIds", [args.ability]);+ query.eq("abilityId", args?.ability);}if (args) {@@ -506,12 +507,14 @@ export async function getLocationsList(client: SupabaseClient<Database>) {export async function getPartner(client: SupabaseClient<Database>,- partnerId: string+ partnerId: string,+ abilityId: string) {return client.from("partners").select("*").eq("supplierLocationId", partnerId)+ .eq("abilityId", abilityId).single();}@@ -526,7 +529,7 @@ export async function getPartners(}if (args?.ability) {- query.contains("abilityIds", [args.ability]);+ query.eq("abilityId", args.ability);}if (args) {@@ -1146,52 +1149,23 @@ export async function upsertLocation(export async function upsertPartner(client: SupabaseClient<Database>,- partnerWithAbilities:- | {- id: string;- hoursPerWeek?: number;- abilities: string[];+ partner:+ | (Omit<TypeOfValidator<typeof partnerValidator>, "supplierId"> & {createdBy: string;- }- | {- id: string;- hoursPerWeek?: number;- abilities: string[];+ })+ | (Omit<TypeOfValidator<typeof partnerValidator>, "supplierId"> & {updatedBy: string;- }+ })) {- const { abilities, ...partner } = partnerWithAbilities;if ("updatedBy" in partner) {- const updatePartner = await client+ return client.from("partner").update(sanitize(partner))- .eq("id", partner.id);- if (updatePartner.error) {- return updatePartner;- }- const deletePartnerAbilities = await client- .from("partnerAbility")- .delete()- .eq("partnerId", partner.id);- if (deletePartnerAbilities.error) {- return deletePartnerAbilities;- }+ .eq("id", partner.id)+ .eq("abilityId", partner.abilityId);} else {- const createPartner = await client.from("partner").insert([partner]);- if (createPartner.error) {- return createPartner;- }+ return await client.from("partner").insert([partner]);}-- const partnerAbilities = abilities.map((ability) => {- return {- partnerId: partner.id,- abilityId: ability,- createdBy: "createdBy" in partner ? partner.createdBy : partner.updatedBy,- };- });-- return client.from("partnerAbility").insert(partnerAbilities);}export async function upsertShift(diff --git a/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx b/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsxindex cba0f462b4..46e09cf988 100644--- a/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx+++ b/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx@@ -6,18 +6,20 @@ import {DrawerFooter,DrawerHeader,DrawerTitle,- FormControl,- FormErrorMessage,- FormLabel,HStack,- ReactSelect,VStack,useMount,} from "@carbon/react";import { useFetcher, useNavigate } from "@remix-run/react";import { useEffect, useMemo } from "react";-import { ValidatedForm, useControlField, useField } from "remix-validated-form";-import { Abilities, Number, Submit, Supplier } from "~/components/Form";+import { ValidatedForm, useControlField } from "remix-validated-form";+import {+ Ability,+ Number,+ SelectControlled,+ Submit,+ Supplier,+} from "~/components/Form";import { usePermissions } from "~/hooks";import type { getSupplierLocations } from "~/modules/purchasing";import { partnerValidator } from "~/modules/resources";@@ -41,9 +43,11 @@ const PartnerForm = ({ initialValues }: PartnerFormProps) => {const supplierLocationFetcher =useFetcher<Awaited<ReturnType<typeof getSupplierLocations>>>();- const onSupplierChange = ({ value }: { value: string | number }) => {- if (value)- supplierLocationFetcher.load(path.to.api.supplierLocations(`${value}`));+ const onSupplierChange = (newValue: { value: string | number } | null) => {+ if (newValue)+ supplierLocationFetcher.load(+ path.to.api.supplierLocations(`${newValue.value}`)+ );};useMount(() => {@@ -74,7 +78,9 @@ const PartnerForm = ({ initialValues }: PartnerFormProps) => {validator={partnerValidator}method="post"action={- isEditing ? path.to.partner(initialValues.id) : path.to.newPartner+ isEditing+ ? path.to.partner(initialValues.id, initialValues.abilityId)+ : path.to.newPartner}defaultValues={initialValues}className="flex flex-col h-full"@@ -95,7 +101,7 @@ const PartnerForm = ({ initialValues }: PartnerFormProps) => {initialLocation={initialValues.id}isReadOnly={isEditing}/>- <Abilities name="abilities" label="Abilities" />+ <Ability name="abilityId" label="Ability" /><Numbername="hoursPerWeek"label="Hours per Week"@@ -119,49 +125,42 @@ const PartnerForm = ({ initialValues }: PartnerFormProps) => {);};-const SUPPLIER_LOCATION_FIELD = "id";-const SupplierLocationsBySupplier = ({supplierLocations,initialLocation,isReadOnly,}: {- supplierLocations: { value: string | number; label: string }[];+ supplierLocations: { value: string; label: string }[];initialLocation?: string;isReadOnly: boolean;}) => {- const { error, getInputProps } = useField(SUPPLIER_LOCATION_FIELD);-- const [supplierLocation, setSupplierLocation] = useControlField<{- value: string | number;- label: string;- } | null>(SUPPLIER_LOCATION_FIELD);+ const [supplierLocation, setSupplierLocation] = useControlField<+ string | null+ >("id");useEffect(() => {// if the initial value is in the options, set it, otherwise set to nullif (supplierLocations) {setSupplierLocation(- supplierLocations.find((s) => s.value === initialLocation) ?? null+ supplierLocations.find((s) => s.value === initialLocation)?.value ??+ null);}// eslint-disable-next-line react-hooks/exhaustive-deps}, [supplierLocations, initialLocation]);+ const onChange = (newValue: { value: string } | null) => {+ setSupplierLocation(newValue?.value ?? null);+ };+return (- <FormControl isInvalid={!!error}>- <FormLabel htmlFor={SUPPLIER_LOCATION_FIELD}>Supplier Location</FormLabel>- <ReactSelect- {...getInputProps({- // @ts-ignore- id: SUPPLIER_LOCATION_FIELD,- })}- options={supplierLocations}- value={supplierLocation}- onChange={setSupplierLocation}- isReadOnly={isReadOnly}- />- {error && <FormErrorMessage>{error}</FormErrorMessage>}- </FormControl>+ <SelectControlled+ name="id"+ options={supplierLocations}+ value={supplierLocation ?? undefined}+ onChange={onChange}+ isReadOnly={isReadOnly}+ />);};diff --git a/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx b/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsxindex 76cf15ff55..4b2bf17fc8 100644--- a/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx+++ b/apps/carbon/app/modules/resources/ui/Partners/PartnersTable/PartnersTable.tsx@@ -27,7 +27,7 @@ const PartnersTable = memo(({ data, count }: PartnersTableProps) => {const columns = useMemo<ColumnDef<(typeof rows)[number]>[]>(() => {return [{- accessorKey: "supplier",+ accessorKey: "supplierName",header: "Supplier",cell: ({ row }) => (<HStack>@@ -51,6 +51,11 @@ const PartnersTable = memo(({ data, count }: PartnersTableProps) => {</>),},+ {+ accessorKey: "abilityName",+ header: "Ability",+ cell: (item) => item.getValue(),+ },{accessorKey: "hoursPerWeek",header: "Hours per Week",@@ -68,7 +73,8 @@ const PartnersTable = memo(({ data, count }: PartnersTableProps) => {onClick={() => {navigate(`${path.to.partner(- row.supplierLocationId!+ row.supplierLocationId!,+ row.abilityId!)}?${params.toString()}`);}}diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx b/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsxindex 150ebc98d2..c0bdb1dc05 100644--- a/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx+++ b/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx@@ -4,53 +4,28 @@ import {CardFooter,CardHeader,CardTitle,- FormControl,- FormErrorMessage,- FormLabel,- ReactSelect,VStack,- useMount,} from "@carbon/react";-import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo } from "react";-import { ValidatedForm, useControlField, useField } from "remix-validated-form";+import { useState } from "react";+import { ValidatedForm } from "remix-validated-form";import {DatePicker,Employee,Hidden,Input,Location,+ Shift,Submit,} from "~/components/Form";-import type { EmployeeJob, getShiftsList } from "~/modules/resources";+import type { EmployeeJob } from "~/modules/resources";import { employeeJobValidator } from "~/modules/resources";-import { path } from "~/utils/path";type PersonJobProps = {job: EmployeeJob;};const PersonJob = ({ job }: PersonJobProps) => {- const shiftFetcher = useFetcher<Awaited<ReturnType<typeof getShiftsList>>>();-- const onLocationChange = (selected: { value: string | number } | null) => {- if (selected?.value)- shiftFetcher.load(path.to.api.shifts(`${selected.value}`));- };-- useMount(() => {- if (job.locationId) shiftFetcher.load(path.to.api.shifts(job.locationId));- });-- const shifts = useMemo(- () =>- shiftFetcher.data?.data?.map((shift) => ({- value: shift.id,- label: shift.name,- })) ?? [],- [shiftFetcher.data]- );-+ const [location, setLocation] = useState<string | null>(job.locationId);return (<ValidatedFormvalidator={employeeJobValidator}@@ -74,11 +49,12 @@ const PersonJob = ({ job }: PersonJobProps) => {<Locationname="locationId"label="Location"- onChange={onLocationChange}+ onChange={(l) => setLocation(l?.value ?? null)}/>- <ShiftByLocation- shifts={shifts}- initialShift={job.shiftId ?? undefined}+ <Shift+ location={location ?? undefined}+ name="shiftId"+ label="Shift"/><Employee name="managerId" label="Manager" /><Hidden name="intent" value="job" />@@ -92,47 +68,4 @@ const PersonJob = ({ job }: PersonJobProps) => {);};-const SHIFT_FIELD = "shiftId";--const ShiftByLocation = ({- shifts,- initialShift,-}: {- shifts: { value: string | number; label: string }[];- initialShift?: string;-}) => {- const { error, getInputProps } = useField(SHIFT_FIELD);-- const [shift, setShift] = useControlField<{- value: string | number;- label: string;- } | null>(SHIFT_FIELD);-- useEffect(() => {- // if the initial value is in the options, set it, otherwise set to null- if (shifts) {- setShift(shifts.find((s) => s.value === initialShift) ?? null);- }- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [shifts, initialShift]);-- return (- <FormControl isInvalid={!!error}>- <FormLabel htmlFor={SHIFT_FIELD}>Shift</FormLabel>- <ReactSelect- {...getInputProps({- // @ts-ignore- id: SHIFT_FIELD,- })}- options={shifts}- value={shift}- onChange={setShift}- // @ts-ignore- w="full"- />- {error && <FormErrorMessage>{error}</FormErrorMessage>}- </FormControl>- );-};-export default PersonJob;diff --git a/apps/carbon/app/routes/api+/sales.customer-locations.ts b/apps/carbon/app/routes/api+/sales.customer-locations.tsindex 8e798e8a2e..3b16018e27 100644--- a/apps/carbon/app/routes/api+/sales.customer-locations.ts+++ b/apps/carbon/app/routes/api+/sales.customer-locations.ts@@ -10,6 +10,8 @@ export async function loader({ request }: LoaderFunctionArgs) {view: "sales",});+ console.log("customer locations endpoint");+const url = new URL(request.url);const searchParams = new URLSearchParams(url.search);const customerId = searchParams.get("customerId") as string;@@ -19,6 +21,8 @@ export async function loader({ request }: LoaderFunctionArgs) {data: [],});+ console.log({ customerId });+const locations = await getCustomerLocations(authorized.client, customerId);if (locations.error) {return json(diff --git a/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx b/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsxindex 3149d0d145..002f4203e9 100644--- a/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx+++ b/apps/carbon/app/routes/x+/part+/$partId.suppliers.new.tsx@@ -42,7 +42,7 @@ export async function action({ request, params }: ActionFunctionArgs) {path.to.partSuppliers(partId),await flash(request,- error(createPartSupplier.error, "Failed to create part supplier.")+ error(createPartSupplier.error, "Failed to create part supplier")));}diff --git a/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx b/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsxindex 7f5dd19bd0..701d882ecc 100644--- a/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx+++ b/apps/carbon/app/routes/x+/resources+/departments.$departmentId.tsx@@ -50,14 +50,12 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, name, color, parentDepartmentId } = validation.data;+ const { id, ...data } = validation.data;if (!id) throw notFound("Department ID was not found");const updateDepartment = await upsertDepartment(client, {id,- name,- color,- parentDepartmentId,+ ...data,updatedBy: userId,});@@ -87,5 +85,7 @@ export default function DepartmentRoute() {parentDepartmentId: department.parentDepartmentId ?? undefined,};+ console.log({ initialValues });+return <DepartmentForm initialValues={initialValues} />;}diff --git a/apps/carbon/app/routes/x+/resources+/departments.new.tsx b/apps/carbon/app/routes/x+/resources+/departments.new.tsxindex e5f6679587..bedfb6f316 100644--- a/apps/carbon/app/routes/x+/resources+/departments.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/departments.new.tsx@@ -26,12 +26,10 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { name, color, parentDepartmentId } = validation.data;+ const { id, ...data } = validation.data;const createDepartment = await upsertDepartment(client, {- name,- color,- parentDepartmentId,+ ...data,createdBy: userId,});diff --git a/apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.tsx b/apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.$abilityId.tsxsimilarity index 84%rename from apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.tsxrename to apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.$abilityId.tsxindex ce98e3378e..72db941d41 100644--- a/apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.tsx+++ b/apps/carbon/app/routes/x+/resources+/partners.$supplierLocationId.$abilityId.tsx@@ -3,8 +3,8 @@ import { json, redirect } from "@remix-run/node";import { useLoaderData } from "@remix-run/react";import { validationError } from "remix-validated-form";import {- getPartner,PartnerForm,+ getPartner,partnerValidator,upsertPartner,} from "~/modules/resources";@@ -19,10 +19,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {view: "resources",});- const { supplierLocationId } = params;+ const { supplierLocationId, abilityId } = params;if (!supplierLocationId) throw notFound("Partner ID was not found");+ if (!abilityId) throw notFound("Ability ID was not found");- const partner = await getPartner(client, supplierLocationId);+ const partner = await getPartner(client, supplierLocationId, abilityId);if (partner.error) {return redirect(@@ -48,13 +49,10 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, hoursPerWeek, abilities } = validation.data;- if (!id) throw notFound("Partner ID was not found");+ const { supplierId, ...data } = validation.data;const updatePartner = await upsertPartner(client, {- id,- hoursPerWeek,- abilities,+ ...data,updatedBy: userId,});@@ -63,7 +61,7 @@ export async function action({ request }: ActionFunctionArgs) {path.to.partners,await flash(request,- error(updatePartner.error, "Failed to create partner.")+ error(updatePartner.error, "Failed to create partner")));}@@ -81,7 +79,7 @@ export default function PartnerRoute() {id: partner.supplierLocationId ?? "",supplierId: partner.supplierId ?? "",hoursPerWeek: partner.hoursPerWeek ?? 0,- abilities: partner.abilityIds ?? ([] as string[]),+ abilityId: partner.abilityId ?? "",};return <PartnerForm initialValues={initialValues} />;diff --git a/apps/carbon/app/routes/x+/resources+/partners.new.tsx b/apps/carbon/app/routes/x+/resources+/partners.new.tsxindex bd5f739822..47852f952e 100644--- a/apps/carbon/app/routes/x+/resources+/partners.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/partners.new.tsx@@ -25,12 +25,10 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const { id, hoursPerWeek, abilities } = validation.data;+ const { supplierId, ...data } = validation.data;const createPartner = await upsertPartner(client, {- id,- hoursPerWeek,- abilities,+ ...data,createdBy: userId,});@@ -39,7 +37,7 @@ export async function action({ request }: ActionFunctionArgs) {path.to.partners,await flash(request,- error(createPartner.error, "Failed to create partner.")+ error(createPartner.error, "Failed to create partner")));}@@ -56,7 +54,7 @@ export default function NewPartnerRoute() {id: params.get("id") ?? "",supplierId: params.get("supplierId") ?? "",hoursPerWeek: 0,- abilities: [] as string[],+ abilityId: "",};return <PartnerForm initialValues={initialValues} />;diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 866b2fd759..86f3851ed5 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -304,7 +304,8 @@ export const path = {partSuppliers: (id: string) => generatePath(`${x}/part/${id}/suppliers`),parts: `${x}/parts`,partsSearch: `${x}/parts/search`,- partner: (id: string) => generatePath(`${x}/resources/partners/${id}`),+ partner: (id: string, abilityId: string) =>+ generatePath(`${x}/resources/partners/${id}/${abilityId}`),partners: `${x}/resources/partners`,paymentTerm: (id: string) =>generatePath(`${x}/accounting/payment-terms/${id}`),diff --git a/packages/database/SCHEMA.md b/packages/database/SCHEMA.mdindex 483d23499f..b9e5ace0c7 100644--- a/packages/database/SCHEMA.md+++ b/packages/database/SCHEMA.md@@ -1430,7 +1430,7 @@ DECLAREBEGINemployee := (SELECT u."fullName" FROM public.user u WHERE u.id = new.id);INSERT INTO public.search(name, entity, uuid, link)- VALUES (employee, 'Person', new.id, '/x/resources/person/' || new.id);+ VALUES (employee, 'Person', new.id, '/x/person/' || new.id);RETURN new;END;$$ LANGUAGE plpgsql SECURITY DEFINER;@@ -2780,40 +2780,34 @@ CREATE POLICY "Employees with resources_delete can delete holidays" ON "holiday"CREATE TABLE "partner" ("id" TEXT NOT NULL,"hoursPerWeek" INTEGER NOT NULL DEFAULT 0,+ "abilityId" TEXT,"active" BOOLEAN NOT NULL DEFAULT true,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"updatedBy" TEXT,"updatedAt" TIMESTAMP WITH TIME ZONE,- CONSTRAINT "partner_pkey" PRIMARY KEY ("id"),+ CONSTRAINT "partner_pkey" PRIMARY KEY ("id", "abilityId"),CONSTRAINT "partner_id_fkey" FOREIGN KEY ("id") REFERENCES "supplierLocation"("id"),+ CONSTRAINT "partner_abilityId_fkey" FOREIGN KEY ("abilityId") REFERENCES "ability"("id"),CONSTRAINT "partner_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),CONSTRAINT "partner_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id"));-CREATE TABLE "partnerAbility" (- "partnerId" TEXT NOT NULL,- "abilityId" TEXT NOT NULL,- "createdBy" TEXT NOT NULL,- "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),-- CONSTRAINT "partnerAbility_pkey" PRIMARY KEY ("partnerId", "abilityId"),- CONSTRAINT "partnerAbility_partnerId_fkey" FOREIGN KEY ("partnerId") REFERENCES "partner"("id") ON DELETE CASCADE,- CONSTRAINT "partnerAbility_abilityId_fkey" FOREIGN KEY ("abilityId") REFERENCES "ability"("id") ON DELETE CASCADE,- CONSTRAINT "partnerAbility_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id")-);+CREATE INDEX "partner_id_idx" ON "partner" ("id");+CREATE INDEX "partner_abilityId_idx" ON "partner" ("abilityId");CREATE OR REPLACE VIEW "partners" ASSELECTp.id AS "supplierLocationId",p."active",- p."hoursPerWeek",+ p."hoursPerWeek",+ p."abilityId",+ a2.name AS "abilityName",s.id AS "supplierId",s.name AS "supplierName",a.city,- a.state,- array_agg(pa."abilityId") AS "abilityIds"+ a.stateFROM "partner" pINNER JOIN "supplierLocation" slON sl.id = p.id@@ -2821,11 +2815,9 @@ CREATE OR REPLACE VIEW "partners" ASON s.id = sl."supplierId"INNER JOIN "address" aON a.id = sl."addressId"- INNER JOIN "partnerAbility" pa- ON pa."partnerId" = p.id- WHERE p."active" = true- GROUP BY p.id, p.active, p."hoursPerWeek", s.id, a.id, s.name, a.city, a.state-;+ INNER JOIN "ability" a2+ ON a2.id = p."abilityId"+ WHERE p."active" = true;```diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 923227d5f0..7817cff33f 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -3929,6 +3929,7 @@ export interface Database {};partner: {Row: {+ abilityId: string;active: boolean;createdAt: string;createdBy: string;@@ -3938,6 +3939,7 @@ export interface Database {updatedBy: string | null;};Insert: {+ abilityId: string;active?: boolean;createdAt?: string;createdBy: string;@@ -3947,6 +3949,7 @@ export interface Database {updatedBy?: string | null;};Update: {+ abilityId?: string;active?: boolean;createdAt?: string;createdBy?: string;@@ -3956,6 +3959,12 @@ export interface Database {updatedBy?: string | null;};Relationships: [+ {+ foreignKeyName: "partner_abilityId_fkey";+ columns: ["abilityId"];+ referencedRelation: "ability";+ referencedColumns: ["id"];+ },{foreignKeyName: "partner_createdBy_fkey";columns: ["createdBy"];@@ -4000,64 +4009,6 @@ export interface Database {}];};- partnerAbility: {- Row: {- abilityId: string;- createdAt: string;- createdBy: string;- partnerId: string;- };- Insert: {- abilityId: string;- createdAt?: string;- createdBy: string;- partnerId: string;- };- Update: {- abilityId?: string;- createdAt?: string;- createdBy?: string;- partnerId?: string;- };- Relationships: [- {- foreignKeyName: "partnerAbility_abilityId_fkey";- columns: ["abilityId"];- referencedRelation: "ability";- referencedColumns: ["id"];- },- {- foreignKeyName: "partnerAbility_createdBy_fkey";- columns: ["createdBy"];- referencedRelation: "user";- referencedColumns: ["id"];- },- {- foreignKeyName: "partnerAbility_createdBy_fkey";- columns: ["createdBy"];- referencedRelation: "employeeSummary";- referencedColumns: ["id"];- },- {- foreignKeyName: "partnerAbility_createdBy_fkey";- columns: ["createdBy"];- referencedRelation: "userDefaults";- referencedColumns: ["userId"];- },- {- foreignKeyName: "partnerAbility_partnerId_fkey";- columns: ["partnerId"];- referencedRelation: "partner";- referencedColumns: ["id"];- },- {- foreignKeyName: "partnerAbility_partnerId_fkey";- columns: ["partnerId"];- referencedRelation: "partners";- referencedColumns: ["supplierLocationId"];- }- ];- };partPlanning: {Row: {createdAt: string;@@ -9455,7 +9406,8 @@ export interface Database {};partners: {Row: {- abilityIds: string[] | null;+ abilityId: string | null;+ abilityName: string | null;active: boolean | null;city: string | null;hoursPerWeek: number | null;@@ -9465,6 +9417,12 @@ export interface Database {supplierName: string | null;};Relationships: [+ {+ foreignKeyName: "partner_abilityId_fkey";+ columns: ["abilityId"];+ referencedRelation: "ability";+ referencedColumns: ["id"];+ },{foreignKeyName: "partner_id_fkey";columns: ["supplierLocationId"];diff --git a/packages/database/supabase/migrations/20230319224154_partners.sql b/packages/database/supabase/migrations/20230319224154_partners.sqlindex 2f2b72141a..b917b6640d 100644--- a/packages/database/supabase/migrations/20230319224154_partners.sql+++ b/packages/database/supabase/migrations/20230319224154_partners.sql@@ -1,40 +1,34 @@CREATE TABLE "partner" ("id" TEXT NOT NULL,"hoursPerWeek" INTEGER NOT NULL DEFAULT 0,+ "abilityId" TEXT,"active" BOOLEAN NOT NULL DEFAULT true,"createdBy" TEXT NOT NULL,"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),"updatedBy" TEXT,"updatedAt" TIMESTAMP WITH TIME ZONE,- CONSTRAINT "partner_pkey" PRIMARY KEY ("id"),+ CONSTRAINT "partner_pkey" PRIMARY KEY ("id", "abilityId"),CONSTRAINT "partner_id_fkey" FOREIGN KEY ("id") REFERENCES "supplierLocation"("id"),+ CONSTRAINT "partner_abilityId_fkey" FOREIGN KEY ("abilityId") REFERENCES "ability"("id"),CONSTRAINT "partner_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id"),CONSTRAINT "partner_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id"));-CREATE TABLE "partnerAbility" (- "partnerId" TEXT NOT NULL,- "abilityId" TEXT NOT NULL,- "createdBy" TEXT NOT NULL,- "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),-- CONSTRAINT "partnerAbility_pkey" PRIMARY KEY ("partnerId", "abilityId"),- CONSTRAINT "partnerAbility_partnerId_fkey" FOREIGN KEY ("partnerId") REFERENCES "partner"("id") ON DELETE CASCADE,- CONSTRAINT "partnerAbility_abilityId_fkey" FOREIGN KEY ("abilityId") REFERENCES "ability"("id") ON DELETE CASCADE,- CONSTRAINT "partnerAbility_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id")-);+CREATE INDEX "partner_id_idx" ON "partner" ("id");+CREATE INDEX "partner_abilityId_idx" ON "partner" ("abilityId");CREATE OR REPLACE VIEW "partners" ASSELECTp.id AS "supplierLocationId",p."active",- p."hoursPerWeek",+ p."hoursPerWeek",+ p."abilityId",+ a2.name AS "abilityName",s.id AS "supplierId",s.name AS "supplierName",a.city,- a.state,- array_agg(pa."abilityId") AS "abilityIds"+ a.stateFROM "partner" pINNER JOIN "supplierLocation" slON sl.id = p.id@@ -42,8 +36,6 @@ CREATE OR REPLACE VIEW "partners" ASON s.id = sl."supplierId"INNER JOIN "address" aON a.id = sl."addressId"- INNER JOIN "partnerAbility" pa- ON pa."partnerId" = p.id- WHERE p."active" = true- GROUP BY p.id, p.active, p."hoursPerWeek", s.id, a.id, s.name, a.city, a.state-;\ No newline at end of file+ INNER JOIN "ability" a2+ ON a2.id = p."abilityId"+ WHERE p."active" = true;\ No newline at end of filediff --git a/packages/react/src/Date/components/DateSegment.tsx b/packages/react/src/Date/components/DateSegment.tsxindex 2e9a1ce217..e0a598aad1 100644--- a/packages/react/src/Date/components/DateSegment.tsx+++ b/packages/react/src/Date/components/DateSegment.tsx@@ -1,11 +1,10 @@-import { Box } from "@chakra-ui/react";import { useDateSegment } from "@react-aria/datepicker";import type {DateSegment as DateSegmentType,useDateFieldState,} from "@react-stately/datepicker";+import clsx from "clsx";import { useId, useRef } from "react";-import { useColor } from "../../hooks";export const DateSegment = ({segment,@@ -25,38 +24,25 @@ export const DateSegment = ({segmentProps["aria-describedby"] = instanceId;}- const lighter = useColor("gray.500");- const light = useColor("gray.600");- const black = useColor("black");-return (- <Box+ <div{...segmentProps}- id={instanceId}ref={ref}- style={{- ...segmentProps.style,- fontVariantNumeric: "tabular-nums",- boxSizing: "content-box",- }}- minWidth={- segment.maxValue !== undefined- ? String(segment.maxValue).length + "ch"- : undefined- }- paddingX="0.5"- textAlign="end"- outline="none"- rounded="md"- color={- segment.isPlaceholder ? lighter : !segment.isEditable ? light : black- }- _focus={{- background: "gray.500",- color: "white",- }}+ className="box-content tabular-nums text-right outline-none rounded-sm group focus:ring-2 focus:ring-offset-2">- {segment.text}- </Box>+ <span+ aria-hidden="true"+ className={clsx("w-full text-center", {+ hidden: !segment.isPlaceholder,+ "h-0": !segment.isPlaceholder,+ block: segment.isPlaceholder,+ })}+ >+ {segment.isPlaceholder+ ? segment.text.toUpperCase()+ : segment.placeholder}+ </span>+ {segment.isPlaceholder ? "" : segment.text}+ </div>);};diff --git a/packages/react/src/Input.tsx b/packages/react/src/Input.tsxindex 4bd0d4f5b6..cb4698a4c8 100644--- a/packages/react/src/Input.tsx+++ b/packages/react/src/Input.tsx@@ -9,7 +9,7 @@ import { getValidChildren } from "~/utils/react";const InputGroupContext = createContext<boolean>(false);const inputGroupVariants = cva(- "flex relative w-full bg-background text-foreground shadow-sm focus-within:outline-none border border-input ring-1 ring-border ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",+ "flex relative w-full bg-background text-foreground shadow-sm focus-within:outline-none border border-input ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",{variants: {size: {diff --git a/www/styles.css b/www/styles.cssindex 6ee20a49e2..f47a41eda0 100644--- a/www/styles.css+++ b/www/styles.css@@ -9,6 +9,10 @@ code {}:root {+ --nextra-primary-hue: 230deg;+}++.dark {--nextra-primary-hue: 161deg;}