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.

2.2 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { ValidatedForm } from "@carbon/form";
import { useAction } from "@carbon/query";
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
  toast
} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { Hidden, Number, Submit } from "~/components/Form";
import { rescheduleToleranceValidator } from "~/modules/settings/settings.models";

// One settings card = one saved concern (archetype F): the reschedule
// tolerance MRP applies before it raises an Expedite / Defer suggestion.

export function RescheduleToleranceCard({
  rescheduleToleranceDays
}: {
  rescheduleToleranceDays: number;
}) {
  const { t } = useLingui();
  const fetcher = useAction({
    onSuccess: () => toast.success(t`Reschedule tolerance updated`)
  });

  return (
    <Card>
      <ValidatedForm
        method="post"
        validator={rescheduleToleranceValidator}
        defaultValues={{ days: rescheduleToleranceDays }}
        fetcher={fetcher}
      >
        <Hidden name="intent" value="setTolerance" />
        <CardHeader>
          <CardTitle>
            <Trans>Reschedule Tolerance</Trans>
          </CardTitle>
          <CardDescription>
            <Trans>
              MRP suggests moving an existing order only when its date is off by
              more than this many days. Smaller gaps are left alone so the
              worklist stays quiet.
            </Trans>
          </CardDescription>
        </CardHeader>
        <CardContent>
          <div className="flex flex-col gap-8 max-w-[400px]">
            <Number
              name="days"
              label={t`Tolerance (days)`}
              minValue={0}
              maxValue={365}
              helperText={t`0 suggests a move for any date difference.`}
            />
          </div>
        </CardContent>
        <CardFooter>
          <Submit isDisabled={fetcher.state !== "idle"}>
            <Trans>Save</Trans>
          </Submit>
        </CardFooter>
      </ValidatedForm>
    </Card>
  );
}