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
wip
neilk174b627b06f583
diff --git a/apps/carbon/app/components/Form/PhoneInput.tsx b/apps/carbon/app/components/Form/PhoneInput.tsxnew file mode 100644index 0000000000..dab03dc5b9--- /dev/null+++ b/apps/carbon/app/components/Form/PhoneInput.tsx@@ -0,0 +1,173 @@+// import { CheckIcon, ChevronsUpDown } from "lucide-react";++import * as React from "react";++import * as ReactPhoneInput from "react-phone-number-input";++import flags from "react-phone-number-input/flags";++import type { InputProps } from "@carbon/react";+import {+ Button,+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ FormControl,+ FormLabel,+ Input,+ Popover,+ PopoverContent,+ PopoverTrigger,+ cn,+} from "@carbon/react";+import { RxCaretSort, RxCheck } from "react-icons/rx";+const PhoneInputComponent = ReactPhoneInput.default;++type PhoneInputProps = InputProps & {+ name: string;+ label?: string;+ isRequired?: boolean;+} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> &+ Omit<ReactPhoneInput.Props<typeof ReactPhoneInput.default>, "onChange"> & {+ onChange: (value: ReactPhoneInput.Value) => void;+ value: ReactPhoneInput.Value;+ };++const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =+ React.forwardRef<+ React.ElementRef<typeof ReactPhoneInput.default>,+ PhoneInputProps+ >(({ name, label, isRequired, className, ...props }, ref) => (+ <FormControl isRequired={isRequired}>+ <FormLabel htmlFor={name}>{label}</FormLabel>+ <PhoneInputComponent+ ref={ref}+ className={cn("flex", className)}+ flagComponent={FlagComponent}+ countrySelectComponent={CountrySelect}+ inputComponent={InputComponent}+ /**+ * Handles the onChange event.+ *+ * react-phone-number-input might trigger the onChange event as undefined+ * when a valid phone number is not entered. To prevent this,+ * the value is coerced to an empty string.+ *+ * @param {E164Number | undefined} value - The entered value+ */+ onChange={(value) => onChange(value || "")}+ {...props}+ />+ </FormControl>+ ));+PhoneInput.displayName = "PhoneInput";++const InputComponent = React.forwardRef<HTMLInputElement, InputProps>(+ ({ className, ...props }, ref) => (+ <Input+ className={cn("rounded-s-none rounded-e-lg", className)}+ {...props}+ ref={ref}+ />+ )+);+InputComponent.displayName = "InputComponent";++type CountrySelectOption = { label: string; value: ReactPhoneInput.Country };++type CountrySelectProps = {+ disabled?: boolean;+ value: ReactPhoneInput.Country;+ onChange: (value: ReactPhoneInput.Country) => void;+ options: CountrySelectOption[];+};++const CountrySelect = ({+ disabled,+ value,+ onChange,+ options,+}: CountrySelectProps) => {+ const handleSelect = React.useCallback(+ (country: ReactPhoneInput.Country) => {+ onChange(country);+ },+ [onChange]+ );++ return (+ <Popover>+ <PopoverTrigger asChild>+ <Button+ variant={"ghost"}+ className={cn(+ "py-1 flex gap-1 h-full rounded-e-none rounded-s-lg pr-1 pl-3"+ )}+ disabled={disabled}+ >+ <FlagComponent country={value} countryName={value} />+ <RxCaretSort+ className={cn(+ "h-4 w-4 opacity-50",+ disabled ? "hidden" : "opacity-100"+ )}+ />+ </Button>+ </PopoverTrigger>+ <PopoverContent className="p-0 w-[300px]">+ <Command>+ <CommandList>+ <CommandInput placeholder="Search country..." />+ <CommandEmpty>No country found.</CommandEmpty>+ <CommandGroup>+ {options+ .filter((x) => x.value)+ .map((option) => (+ <CommandItem+ className="gap-2"+ key={option.value}+ onSelect={() => handleSelect(option.value)}+ >+ <FlagComponent+ country={option.value}+ countryName={option.label}+ />+ <span className="text-sm flex-1">{option.label}</span>+ {option.value && (+ <span className="text-sm text-foreground/50">+ {`+${ReactPhoneInput.getCountryCallingCode(+ option.value+ )}`}+ </span>+ )}+ <RxCheck+ className={cn(+ "ml-auto h-4 w-4",+ option.value === value ? "opacity-100" : "opacity-0"+ )}+ />+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ );+};++const FlagComponent = ({ country, countryName }: ReactPhoneInput.FlagProps) => {+ const Flag = flags[country];++ return (+ <span className="flex h-4 w-6 overflow-hidden rounded-sm bg-foreground/20">+ {Flag && <Flag title={countryName} />}+ </span>+ );+};+FlagComponent.displayName = "FlagComponent";++export default PhoneInput;diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.tsindex 4609032148..33ac52fb4c 100644--- a/apps/carbon/app/components/Form/index.ts+++ b/apps/carbon/app/components/Form/index.ts@@ -27,6 +27,7 @@ import NumberControlled from "./NumberControlled";import Part from "./Part";import Password from "./Password";import Phone from "./Phone";+import PhoneInput from "./PhoneInput";import Radios from "./Radios";import RichText from "./RichText";import Select from "./Select";@@ -76,6 +77,7 @@ export {Part,Password,Phone,+ PhoneInput,Radios,RichText,Select,diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsxindex c342dd5ab5..16e864d2c6 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerContactForm.tsx@@ -16,6 +16,7 @@ import {Hidden,Input,Phone,+ PhoneInput,Submit,TextArea,} from "~/components/Form";@@ -73,6 +74,7 @@ const CustomerContactForm = ({ initialValues }: CustomerContactFormProps) => {<Input name="lastName" label="Last Name" /><Input name="email" label="Email" /><Input name="title" label="Title" />+ <PhoneInput name="mobilePhone" label="Mobile Phone" /><Phone name="mobilePhone" label="Mobile Phone" /><Phone name="homePhone" label="Home Phone" /><Phone name="workPhone" label="Work Phone" />diff --git a/package-lock.json b/package-lock.jsonindex d5a001d30b..03cf1f807f 100644--- a/package-lock.json+++ b/package-lock.json@@ -11,6 +11,9 @@"shared","www"],+ "dependencies": {+ "react-phone-number-input": "^3.3.9"+ },"devDependencies": {"eslint": "^8.23.1","eslint-config-carbon": "*",@@ -12213,6 +12216,11 @@"layout-base": "^1.0.0"}},+ "node_modules/country-flag-icons": {+ "version": "1.5.9",+ "resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.5.9.tgz",+ "integrity": "sha512-9jrjv2w7kRbqNtdtMdK2j3gmDIZzd5l9L2pZiQjF9J0mUcB+NKIGDNADTDHBEp8EQtjOkCOcciJGGSOpERdXPQ=="+ },"node_modules/crelt": {"version": "1.0.6","resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",@@ -16971,6 +16979,14 @@"resolved": "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.1.1.tgz","integrity": "sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q=="},+ "node_modules/input-format": {+ "version": "0.3.9",+ "resolved": "https://registry.npmjs.org/input-format/-/input-format-0.3.9.tgz",+ "integrity": "sha512-99Gew2huiuYpNsyZoucauy5OT3oXEoWUeINGES4SlU74eFxbtYqNO+yEP6uKFhfB0UKTvq4gOC+6/3Oskru+IQ==",+ "dependencies": {+ "prop-types": "^15.8.1"+ }+ },"node_modules/inquirer": {"version": "9.2.15","resolved": "https://registry.npmjs.org/inquirer/-/inquirer-9.2.15.tgz",@@ -19249,6 +19265,11 @@"node": ">= 0.8.0"}},+ "node_modules/libphonenumber-js": {+ "version": "1.10.57",+ "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.57.tgz",+ "integrity": "sha512-OjsEd9y4LgcX+Ig09SbxWqcGESxliDDFNVepFhB9KEsQZTrnk3UdEU+cO0sW1APvLprHstQpS23OQpZ3bwxy6Q=="+ },"node_modules/lie": {"version": "3.1.1","resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",@@ -25466,6 +25487,22 @@"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz","integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="},+ "node_modules/react-phone-number-input": {+ "version": "3.3.9",+ "resolved": "https://registry.npmjs.org/react-phone-number-input/-/react-phone-number-input-3.3.9.tgz",+ "integrity": "sha512-TKK8VoFWR9RfPi90j/3Rr6j/S9V8/eovqUgNNNSyD0+WtaeLTlJVWb8DD7P57eZqkLv303sL8JMiZoExwKICxw==",+ "dependencies": {+ "classnames": "^2.3.1",+ "country-flag-icons": "^1.5.4",+ "input-format": "^0.3.9",+ "libphonenumber-js": "^1.10.53",+ "prop-types": "^15.8.1"+ },+ "peerDependencies": {+ "react": ">=16.8",+ "react-dom": ">=16.8"+ }+ },"node_modules/react-refresh": {"version": "0.14.0","resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz",diff --git a/package.json b/package.jsonindex ad74536087..a0d52ed092 100755--- a/package.json+++ b/package.json@@ -64,5 +64,8 @@"packages/*","shared","www"- ]+ ],+ "dependencies": {+ "react-phone-number-input": "^3.3.9"+ }}