Skip to content

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.

erp: apply optional labels across shared form wrappers

Sid Gaikwadb57b561d6a4c
diff --git a/apps/erp/app/components/Form/AddressAutocomplete.tsx b/apps/erp/app/components/Form/AddressAutocomplete.tsx
index 2651d51cbc..a842d15892 100644
--- a/apps/erp/app/components/Form/AddressAutocomplete.tsx
+++ b/apps/erp/app/components/Form/AddressAutocomplete.tsx
@@ -29,7 +29,7 @@ const AddressAutocomplete = ({
const [value, setValue] = useControlField<string>(address1Field);
const { clearError } = useFormContext();
- const { error } = useField(address1Field);
+ const { error, isOptional: isAddressLine1Optional } = useField(address1Field);
const [open, setOpen] = useState(false);
const [justSelected, setJustSelected] = useState(false);
const [userInteracted, setUserInteracted] = useState(false);
@@ -148,7 +148,9 @@ const AddressAutocomplete = ({
const addressAutocompleteField = (
<FormControl isInvalid={!!error}>
- <FormLabel htmlFor={address1Field}>{t`Address Line 1`}</FormLabel>
+ <FormLabel htmlFor={address1Field} isOptional={isAddressLine1Optional}>
+ {t`Address Line 1`}
+ </FormLabel>
<div className="relative w-full" ref={containerRef}>
<Command shouldFilter={false} className="bg-transparent">
<CommandInputTextField
diff --git a/apps/erp/app/components/Form/Color.tsx b/apps/erp/app/components/Form/Color.tsx
index 728309b84c..4f55e40daa 100644
--- a/apps/erp/app/components/Form/Color.tsx
+++ b/apps/erp/app/components/Form/Color.tsx
@@ -16,7 +16,7 @@ type ColorFieldProps = {
};
const ColorPicker = ({ name, label }: ColorFieldProps) => {
- const { error } = useField(name);
+ const { error, isOptional: fieldIsOptional } = useField(name);
const [value, setValue] = useControlField<string>(name);
const disclosure = useDisclosure();
const containerRef = useRef<HTMLDivElement>(null);
@@ -28,7 +28,7 @@ const ColorPicker = ({ name, label }: ColorFieldProps) => {
return (
<FormControl>
- <FormLabel>{label}</FormLabel>
+ <FormLabel isOptional={fieldIsOptional}>{label}</FormLabel>
<input type="hidden" name={name} value={value} />
<div className="relative" ref={containerRef}>
<HStack>
diff --git a/apps/erp/app/components/Form/ConversionFactor.tsx b/apps/erp/app/components/Form/ConversionFactor.tsx
index 01438fd5e1..c093fd3634 100644
--- a/apps/erp/app/components/Form/ConversionFactor.tsx
+++ b/apps/erp/app/components/Form/ConversionFactor.tsx
@@ -68,7 +68,12 @@ const ConversionFactor = forwardRef<
ref
) => {
const { t } = useLingui();
- const { getInputProps, error, defaultValue } = useField(name);
+ const {
+ getInputProps,
+ error,
+ defaultValue,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [controlValue, setControlValue] = useControlField<number>(name);
const [open, setOpen] = useState(false);
@@ -181,10 +186,15 @@ const ConversionFactor = forwardRef<
setConversionFactor(initialValue.current);
setOpen(false);
};
+ const resolvedIsOptional = isRequired ? false : (fieldIsOptional ?? false);
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}
+ {label && (
+ <FormLabel htmlFor={name} isOptional={resolvedIsOptional}>
+ {label}
+ </FormLabel>
+ )}
<input
{...getInputProps({
id: name
diff --git a/apps/erp/app/components/Form/EmailRecipients.tsx b/apps/erp/app/components/Form/EmailRecipients.tsx
index 13e0687465..a0b956ad58 100644
--- a/apps/erp/app/components/Form/EmailRecipients.tsx
+++ b/apps/erp/app/components/Form/EmailRecipients.tsx
@@ -125,7 +125,12 @@ export default function EmailRecipients({
helperText,
type = "employee"
}: EmailRecipientsProps) {
- const { error, defaultValue, validate } = useField(name);
+ const {
+ error,
+ defaultValue,
+ validate,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [emails, setEmails] = useState<string[]>(defaultValue ?? []);
const [inputValue, setInputValue] = useState("");
const [inputError, setInputError] = useState(false);
@@ -219,7 +224,11 @@ export default function EmailRecipients({
return (
<FormControl isInvalid={!!error}>
- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}
+ {label && (
+ <FormLabel htmlFor={name} isOptional={fieldIsOptional}>
+ {label}
+ </FormLabel>
+ )}
{emails.map((email, index) => (
<input
key={email}
diff --git a/apps/erp/app/components/Form/Employees.tsx b/apps/erp/app/components/Form/Employees.tsx
index 27a9ea2ba3..865ac9b811 100644
--- a/apps/erp/app/components/Form/Employees.tsx
+++ b/apps/erp/app/components/Form/Employees.tsx
@@ -19,7 +19,12 @@ export type EmployeesProps = {
} & UserSelectProps;
const Employees = ({ name, label, helperText, ...props }: EmployeesProps) => {
- const { error, defaultValue, validate } = useField(name);
+ const {
+ error,
+ defaultValue,
+ validate,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [selections, setSelections] = useState<string[]>(defaultValue);
const handleChange = (items: IndividualOrGroup[]) => {
@@ -29,7 +34,11 @@ const Employees = ({ name, label, helperText, ...props }: EmployeesProps) => {
return (
<FormControl isInvalid={!!error}>
- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}
+ {label && (
+ <FormLabel htmlFor={name} isOptional={fieldIsOptional}>
+ {label}
+ </FormLabel>
+ )}
{selections.map((selection, index) => (
<input
key={`${name}[${index}]`}
diff --git a/apps/erp/app/components/Form/Item.tsx b/apps/erp/app/components/Form/Item.tsx
index 8246357e0f..588b6ca848 100644
--- a/apps/erp/app/components/Form/Item.tsx
+++ b/apps/erp/app/components/Form/Item.tsx
@@ -88,7 +88,7 @@ const Item = ({
label,
helperText,
isConfigured = false,
- isOptional = false,
+ isOptional,
type = "Part",
typeFieldName = "itemType",
validItemTypes,
@@ -159,8 +159,9 @@ const Item = ({
const [created, setCreated] = useState<string>("");
const triggerRef = useRef<HTMLButtonElement>(null);
- const { getInputProps, error } = useField(name);
+ const { getInputProps, error, isOptional: fieldIsOptional } = useField(name);
const [value, setValue] = useControlField<string | undefined>(name);
+ const resolvedIsOptional = isOptional ?? fieldIsOptional ?? false;
useEffect(() => {
if (props.value !== null && props.value !== undefined)
@@ -185,7 +186,7 @@ const Item = ({
<FormLabel
htmlFor={name}
isConfigured={isConfigured}
- isOptional={isOptional}
+ isOptional={resolvedIsOptional}
onConfigure={onConfigure}
>
{translateItemType(type)}
@@ -218,7 +219,7 @@ const Item = ({
setValue(newValue?.replace(/"/g, '\\"') ?? "");
onChange(newValue?.replace(/"/g, '\\"') ?? "");
}}
- isClearable={isOptional && !props.isReadOnly}
+ isClearable={resolvedIsOptional && !props.isReadOnly}
label={
label === "Item"
? t`Item`
diff --git a/apps/erp/app/components/Form/SequenceOrCustomId.tsx b/apps/erp/app/components/Form/SequenceOrCustomId.tsx
index 6223344e8d..dd04e25618 100644
--- a/apps/erp/app/components/Form/SequenceOrCustomId.tsx
+++ b/apps/erp/app/components/Form/SequenceOrCustomId.tsx
@@ -32,7 +32,7 @@ const SequenceOrCustomId = forwardRef<
name,
label,
table,
- isOptional = false,
+ isOptional,
helperText,
placeholder: placeholderProp,
...rest
@@ -41,13 +41,18 @@ const SequenceOrCustomId = forwardRef<
) => {
const { t } = useLingui();
const placeholder = placeholderProp ?? t`Next Sequence`;
- const { getInputProps, error } = useField(name);
+ const {
+ getInputProps,
+ error,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [isCustom, setIsCustom] = useState(!!getInputProps()?.defaultValue);
+ const resolvedIsOptional = isOptional ?? fieldIsOptional ?? false;
return (
<FormControl isInvalid={!!error}>
{label && (
- <FormLabel htmlFor={name} isOptional={isOptional}>
+ <FormLabel htmlFor={name} isOptional={resolvedIsOptional}>
{label}
</FormLabel>
)}
diff --git a/apps/erp/app/components/Form/Tool.tsx b/apps/erp/app/components/Form/Tool.tsx
index 83092a294c..849ef158cc 100644
--- a/apps/erp/app/components/Form/Tool.tsx
+++ b/apps/erp/app/components/Form/Tool.tsx
@@ -55,7 +55,7 @@ const Tool = ({ name, label, helperText, ...props }: ToolSelectProps) => {
const [created, setCreated] = useState<string>("");
const triggerRef = useRef<HTMLButtonElement>(null);
- const { getInputProps, error } = useField(name);
+ const { getInputProps, error, isOptional: fieldIsOptional } = useField(name);
const [value, setValue] = useControlField<string | undefined>(name);
useEffect(() => {
@@ -74,7 +74,7 @@ const Tool = ({ name, label, helperText, ...props }: ToolSelectProps) => {
return (
<>
<FormControl isInvalid={!!error} className="w-full">
- {label && <FormLabel>{label}</FormLabel>}
+ {label && <FormLabel isOptional={fieldIsOptional}>{label}</FormLabel>}
<input
{...getInputProps({
id: name
diff --git a/apps/erp/app/components/Form/User.tsx b/apps/erp/app/components/Form/User.tsx
index ef1d0103ed..553c689138 100644
--- a/apps/erp/app/components/Form/User.tsx
+++ b/apps/erp/app/components/Form/User.tsx
@@ -19,7 +19,12 @@ export type UserProps = {
} & UserSelectProps;
const User = ({ name, label, type, helperText, ...props }: UserProps) => {
- const { error, defaultValue, validate } = useField(name);
+ const {
+ error,
+ defaultValue,
+ validate,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [selection, setSelection] = useState<string>(defaultValue);
const handleChange = (items: IndividualOrGroup[]) => {
@@ -34,7 +39,11 @@ const User = ({ name, label, type, helperText, ...props }: UserProps) => {
return (
<FormControl isInvalid={!!error}>
- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}
+ {label && (
+ <FormLabel htmlFor={name} isOptional={fieldIsOptional}>
+ {label}
+ </FormLabel>
+ )}
<input type="hidden" name={name} value={selection} />
<UserSelect
{...props}
diff --git a/apps/erp/app/components/Form/Users.tsx b/apps/erp/app/components/Form/Users.tsx
index 70a4ae269f..1b2689ace8 100644
--- a/apps/erp/app/components/Form/Users.tsx
+++ b/apps/erp/app/components/Form/Users.tsx
@@ -27,7 +27,12 @@ const Users = ({
verbose = false,
...props
}: UsersProps) => {
- const { error, defaultValue, validate } = useField(name);
+ const {
+ error,
+ defaultValue,
+ validate,
+ isOptional: fieldIsOptional
+ } = useField(name);
const [selections, setSelections] = useState<string[]>(defaultValue);
const handleChange = (items: IndividualOrGroup[]) => {
@@ -43,7 +48,11 @@ const Users = ({
return (
<FormControl isInvalid={!!error}>
- {label && <FormLabel htmlFor={name}>{label}</FormLabel>}
+ {label && (
+ <FormLabel htmlFor={name} isOptional={fieldIsOptional}>
+ {label}
+ </FormLabel>
+ )}
{selections.map((selection, index) => (
<input
key={`${name}[${index}]`}
diff --git a/apps/erp/app/components/Selectors/UserSelect/UserSelect.tsx b/apps/erp/app/components/Selectors/UserSelect/UserSelect.tsx
index 3bca26580d..c029168272 100644
--- a/apps/erp/app/components/Selectors/UserSelect/UserSelect.tsx
+++ b/apps/erp/app/components/Selectors/UserSelect/UserSelect.tsx
@@ -33,14 +33,14 @@ const UserSelect = (props: UserSelectProps) => {
const state = useUserSelect(props);
const {
dropdown,
- innerProps: { hideSelections, isMulti, label, readOnly, width },
+ innerProps: { hideSelections, isMulti, isOptional, label, readOnly, width },
refs: { containerRef },
selectionItemsById
} = state;
return (
<UserSelectContext.Provider value={state}>
- {label && <FormLabel>{label}</FormLabel>}
+ {label && <FormLabel isOptional={isOptional}>{label}</FormLabel>}
<Container ref={containerRef} width={width}>
{!(readOnly && isMulti) && (
<Combobox>
diff --git a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
index d8aaa73613..f2b8aed2a1 100644
--- a/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
+++ b/apps/erp/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx
@@ -385,7 +385,7 @@ const PurchaseInvoiceLineForm = ({
/>
<FormControl className="col-span-2">
- <FormLabel>Description</FormLabel>
+ <FormLabel isOptional>Description</FormLabel>
<Input
value={itemData.description}
onChange={(e) =>
diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
index 8a325f51cf..8a6a9866cf 100644
--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
@@ -373,7 +373,7 @@ const SalesInvoiceLineForm = ({
/>
<FormControl className="col-span-2">
- <FormLabel>{t`Description`}</FormLabel>
+ <FormLabel isOptional>{t`Description`}</FormLabel>
<Input
value={itemData.description}
onChange={(e) =>
diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
index 531566f286..40709a66ac 100644
--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx
@@ -416,7 +416,7 @@ const PurchaseOrderLineForm = ({
/>
<FormControl>
- <FormLabel>Description</FormLabel>
+ <FormLabel isOptional>Description</FormLabel>
<Input
value={itemData.description}
onChange={(e) =>
diff --git a/apps/erp/app/modules/users/ui/Customers/CreateCustomerModal.tsx b/apps/erp/app/modules/users/ui/Customers/CreateCustomerModal.tsx
index 9e6c6f2ba4..4f1f792c79 100644
--- a/apps/erp/app/modules/users/ui/Customers/CreateCustomerModal.tsx
+++ b/apps/erp/app/modules/users/ui/Customers/CreateCustomerModal.tsx
@@ -137,7 +137,11 @@ const CustomerContact = ({
) => void;
}) => {
const initialLoad = useRef(true);
- const { error, defaultValue } = useField(name);
+ const {
+ error,
+ defaultValue,
+ isOptional: isCustomerContactOptional
+ } = useField(name);
const [value, setValue] = useControlField<string | null>(name);
const customerContactFetcher =
@@ -193,7 +197,7 @@ const CustomerContact = ({
return (
<FormControl isInvalid={!!error}>
- <FormLabel htmlFor={name}>
+ <FormLabel htmlFor={name} isOptional={isCustomerContactOptional}>
<Trans>Customer Contact</Trans>
</FormLabel>
<input type="hidden" name={name} id={name} value={value ?? ""} />
diff --git a/apps/erp/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx b/apps/erp/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
index 166466b374..2b94700501 100644
--- a/apps/erp/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
+++ b/apps/erp/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
@@ -137,7 +137,11 @@ const SupplierContact = ({
) => void;
}) => {
const initialLoad = useRef(true);
- const { error, defaultValue } = useField(name);
+ const {
+ error,
+ defaultValue,
+ isOptional: isSupplierContactOptional
+ } = useField(name);
const [value, setValue] = useControlField<string | null>(name);
const supplierContactFetcher =
@@ -193,7 +197,7 @@ const SupplierContact = ({
return (
<FormControl isInvalid={!!error}>
- <FormLabel htmlFor={name}>
+ <FormLabel htmlFor={name} isOptional={isSupplierContactOptional}>
<Trans>Supplier Contact</Trans>
</FormLabel>
<input type="hidden" name={name} id={name} value={value ?? ""} />