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.

feat: remove ability

Brad Barbin1f460d6ed3a2
diff --git a/apps/erp/app/modules/resources/resources.models.ts b/apps/erp/app/modules/resources/resources.models.ts
index 832ada1f37..95ea459433 100644
--- a/apps/erp/app/modules/resources/resources.models.ts
+++ b/apps/erp/app/modules/resources/resources.models.ts
@@ -41,9 +41,9 @@ export const contractorValidator = z.object({
hoursPerWeek: zfd.numeric(
z.number().min(0, { message: "Hours are required" })
),
- abilities: z
- .array(z.string().min(20, { message: "Invalid ability" }))
- .optional(),
+ // abilities: z
+ // .array(z.string().min(20, { message: "Invalid ability" }))
+ // .optional(),
assignee: zfd.text(z.string().optional()),
});
@@ -85,7 +85,7 @@ export const partnerValidator = z.object({
hoursPerWeek: zfd.numeric(
z.number().min(0, { message: "Hours are required" })
),
- abilityId: z.string().min(20, { message: "Invalid ability" }),
+ // abilityId: z.string().min(20, { message: "Invalid ability" }),
});
export const processValidator = z
@@ -131,5 +131,5 @@ export const workCenterValidator = z.object({
processes: z
.array(z.string().min(20, { message: "Invalid process" }))
.optional(),
- requiredAbilityId: zfd.text(z.string().optional()),
+ // requiredAbilityId: zfd.text(z.string().optional()),
});
diff --git a/apps/erp/app/modules/resources/ui/Abilities/AbilitiesTable.tsx b/apps/erp/app/modules/resources/ui/Abilities/AbilitiesTable.tsx
deleted file mode 100644
index 93aa338380..0000000000
--- a/apps/erp/app/modules/resources/ui/Abilities/AbilitiesTable.tsx
+++ /dev/null
@@ -1,120 +0,0 @@
-import { Badge, MenuIcon, MenuItem } from "@carbon/react";
-import { useNavigate } from "@remix-run/react";
-import type { ColumnDef } from "@tanstack/react-table";
-import { memo, useCallback, useMemo } from "react";
-import { LuBrain, LuClock, LuPencil, LuTrash, LuUsers } from "react-icons/lu";
-import { EmployeeAvatarGroup, Hyperlink, New, Table } from "~/components";
-import { usePermissions, useUrlParams } from "~/hooks";
-import { path } from "~/utils/path";
-import type { Abilities, AbilityDatum } from "../../types";
-
-type AbilitiesTableProps = {
- data: Abilities;
- count: number;
-};
-
-const AbilitiesTable = memo(({ data, count }: AbilitiesTableProps) => {
- const navigate = useNavigate();
- const permissions = usePermissions();
- const [params] = useUrlParams();
-
- const rows = data.map((row) => ({
- id: row.id,
- name: row.name,
- // @ts-ignore
- weeks: row.curve?.data.at(-1).week,
- curve: row.curve as { data: AbilityDatum[] },
- shadowWeeks: row.shadowWeeks,
- employees: row.employeeAbility?.map(
- (employeeAbility) => employeeAbility.employeeId
- ),
- }));
-
- const columns = useMemo<ColumnDef<(typeof rows)[number]>[]>(() => {
- return [
- {
- accessorKey: "name",
- header: "Ability",
- cell: ({ row }) => (
- <Hyperlink to={path.to.ability(row.original.id)}>
- <Badge variant="secondary" className="cursor-pointer">
- {row.original.name}
- </Badge>
- </Hyperlink>
- ),
- meta: {
- icon: <LuBrain />,
- },
- },
- {
- header: "Employees",
- // accessorKey: undefined, // makes the column unsortable
- cell: ({ row }) => (
- <EmployeeAvatarGroup
- employeeIds={row.original.employees}
- size="xs"
- limit={3}
- />
- ),
- meta: {
- icon: <LuUsers />,
- },
- },
- {
- header: "Time to Learn",
- cell: ({ row }) => `${row.original.weeks} weeks`,
- meta: {
- icon: <LuClock />,
- },
- },
- ];
- }, []);
-
- const renderContextMenu = useCallback(
- (row: (typeof rows)[number]) => {
- return (
- <>
- <MenuItem
- onClick={() => {
- navigate(path.to.ability(row.id));
- }}
- >
- <MenuIcon icon={<LuPencil />} />
- Edit Ability
- </MenuItem>
- <MenuItem
- destructive
- disabled={!permissions.can("delete", "resources")}
- onClick={() => {
- navigate(path.to.deleteAbility(row.id));
- }}
- >
- <MenuIcon icon={<LuTrash />} />
- Delete Ability
- </MenuItem>
- </>
- );
- },
- [navigate, permissions]
- );
-
- return (
- <Table<(typeof rows)[number]>
- data={rows}
- count={count}
- columns={columns}
- primaryAction={
- permissions.can("create", "resources") && (
- <New label="Ability" to={`new?${params.toString()}`} />
- )
- }
- renderContextMenu={renderContextMenu}
- title="Abilities"
- table="ability"
- withSavedView
- />
- );
-});
-
-AbilitiesTable.displayName = "AbilitiesTable";
-export default AbilitiesTable;
diff --git a/apps/erp/app/modules/resources/ui/Abilities/AbilityEmployeesTable.tsx b/apps/erp/app/modules/resources/ui/Abilities/AbilityEmployeesTable.tsx
deleted file mode 100644
index 0c1586b0dc..0000000000
--- a/apps/erp/app/modules/resources/ui/Abilities/AbilityEmployeesTable.tsx
+++ /dev/null
@@ -1,147 +0,0 @@
-import {
- Badge,
- DropdownMenuIcon,
- HStack,
- MenuItem,
- Progress,
-} from "@carbon/react";
-import { useNavigate, useParams } from "@remix-run/react";
-import type { ColumnDef } from "@tanstack/react-table";
-import { useCallback, useMemo } from "react";
-import { LuPencil, LuTrash } from "react-icons/lu";
-import { EmployeeAvatar, New, Table } from "~/components";
-import { usePermissions } from "~/hooks";
-import { AbilityEmployeeStatus, type AbilityEmployees } from "../../types";
-
-import { path } from "~/utils/path";
-
-type AbilityEmployeeTableProps = {
- employees: AbilityEmployees;
- weeks: number;
-};
-
-const AbilityEmployeesTable = ({
- employees,
- weeks,
-}: AbilityEmployeeTableProps) => {
- const { abilityId } = useParams();
-
- if (!abilityId) throw new Error("abilityId not found");
-
- const navigate = useNavigate();
- const permissions = usePermissions();
-
- const rows = useMemo(
- () =>
- Array.isArray(employees)
- ? employees.map((employee) => {
- return {
- id: employee.id,
- employeeId: employee.employeeId,
- status: employee.trainingCompleted
- ? AbilityEmployeeStatus.Complete
- : employee.trainingDays
- ? AbilityEmployeeStatus.InProgress
- : AbilityEmployeeStatus.NotStarted,
- percentage: (employee.trainingDays / 5 / weeks) * 100,
- };
- })
- : [],
- [employees, weeks]
- );
-
- const columns = useMemo<ColumnDef<(typeof rows)[number]>[]>(() => {
- return [
- {
- accessorKey: "name",
- header: "Name",
- cell: ({ row }) => (
- <HStack>
- <EmployeeAvatar employeeId={row.original.employeeId} />
- </HStack>
- ),
- },
- {
- header: "Training Status",
- cell: ({ row }) => {
- const status = row.original.status;
- return (
- <Badge
- variant={
- status === AbilityEmployeeStatus.Complete
- ? "default"
- : status === AbilityEmployeeStatus.InProgress
- ? "outline"
- : "secondary"
- }
- >
- {status}
- </Badge>
- );
- },
- },
- {
- header: "Training Progress",
- width: 200,
- cell: ({ row }) => {
- const percentage = row.original.percentage;
- return (
- <Progress
- className="max-w-[200px]"
- value={
- row.original.status === AbilityEmployeeStatus.Complete
- ? 100
- : percentage
- }
- />
- );
- },
- },
- ];
- }, []);
-
- const renderContextMenu = useCallback(
- (row: (typeof rows)[number]) => {
- return (
- <>
- <MenuItem
- disabled={!permissions.can("update", "resources")}
- onClick={() => {
- navigate(path.to.employeeAbility(abilityId, row.id));
- }}
- >
- <DropdownMenuIcon icon={<LuPencil />} />
- Edit Employee Ability
- </MenuItem>
- <MenuItem
- destructive
- disabled={!permissions.can("delete", "resources")}
- onClick={() => {
- navigate(path.to.deleteEmployeeAbility(abilityId, row.id));
- }}
- >
- <DropdownMenuIcon icon={<LuTrash />} />
- Delete Employee Ability
- </MenuItem>
- </>
- );
- },
- [abilityId, navigate, permissions]
- );
-
- if (!abilityId) return null;
- return (
- <Table<(typeof rows)[number]>
- data={rows}
- count={rows.length}
- columns={columns}
- primaryAction={<New to="employee/new" label="Employee" />}
- renderContextMenu={renderContextMenu}
- withPagination={false}
- withSearch={false}
- title="Ability Employees"
- />
- );
-};
-
-export default AbilityEmployeesTable;
diff --git a/apps/erp/app/modules/resources/ui/Abilities/AbilityForm.tsx b/apps/erp/app/modules/resources/ui/Abilities/AbilityForm.tsx
deleted file mode 100644
index 86c331ff62..0000000000
--- a/apps/erp/app/modules/resources/ui/Abilities/AbilityForm.tsx
+++ /dev/null
@@ -1,119 +0,0 @@
-import {
- Button,
- Drawer,
- DrawerBody,
- DrawerContent,
- DrawerFooter,
- DrawerHeader,
- DrawerTitle,
- HStack,
- VStack,
-} from "@carbon/react";
-
-import { ValidatedForm } from "@carbon/form";
-import { useNavigate } from "@remix-run/react";
-import { useState } from "react";
-import type { z } from "zod";
-import {
- Employees,
- Hidden,
- Input,
- Number,
- Select,
- Submit,
-} from "~/components/Form";
-import { usePermissions } from "~/hooks";
-import { path } from "~/utils/path";
-import { abilityValidator } from "../../resources.models";
-
-type AbilityFormProps = {
- initialValues: z.infer<typeof abilityValidator>;
-};
-
-const AbilityForm = ({ initialValues }: AbilityFormProps) => {
- const permissions = usePermissions();
- const navigate = useNavigate();
- const onClose = () => navigate(-1);
- const [maxShadowWeeks, setMaxShadowWeeks] = useState(initialValues.weeks);
- // const [equipmentRequired, setEquipmentRequired] = useState(initialValues.equipmentType !== undefined);
-
- const onWeekChange = (value: number) => {
- setMaxShadowWeeks(value);
- };
-
- const isDisabled = !permissions.can("create", "resources");
-
- return (
- <Drawer
- open
- onOpenChange={(open) => {
- if (!open) onClose();
- }}
- >
- <DrawerContent>
- <ValidatedForm
- validator={abilityValidator}
- method="post"
- action={path.to.newAbility}
- defaultValues={initialValues}
- className="flex flex-col h-full"
- >
- <DrawerHeader>
- <DrawerTitle>New Ability</DrawerTitle>
- </DrawerHeader>
- <DrawerBody>
- <Hidden name="id" />
- <VStack spacing={4}>
- <Input name="name" label="Name" />
- {/* <Boolean
- name="machineOperator"
- label="Equipment Required"
- description="This ability requires specific equipment"
-
- /> */}
- <Select
- name="startingPoint"
- label="Learning Curve"
- options={[
- { value: "85", label: "Easy" },
- { value: "70", label: "Medium" },
- { value: "50", label: "Hard" },
- ]}
- />
- <Number
- name="weeks"
- label="Time to Efficiency (Weeks)"
- onChange={onWeekChange}
- minValue={0}
- maxValue={52}
- />
- <Number
- name="shadowWeeks"
- label="Time Shadowing (Weeks)"
- helperText="Non-productive time spent shadowing another employee"
- minValue={0}
- maxValue={maxShadowWeeks}
- />
- <Employees
- name="employees"
- selectionsMaxHeight={"calc(100vh - 330px)"}
- label="Employees"
- helperText="Employees who already have this ability"
- />
- </VStack>
- </DrawerBody>
- <DrawerFooter>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </DrawerFooter>
- </ValidatedForm>
- </DrawerContent>
- </Drawer>
- );
-};
-
-export default AbilityForm;
diff --git a/apps/erp/app/modules/resources/ui/Abilities/EmployeeAbilityForm.tsx b/apps/erp/app/modules/resources/ui/Abilities/EmployeeAbilityForm.tsx
deleted file mode 100644
index e8cd0f787c..0000000000
--- a/apps/erp/app/modules/resources/ui/Abilities/EmployeeAbilityForm.tsx
+++ /dev/null
@@ -1,150 +0,0 @@
-import {
- Button,
- Drawer,
- DrawerBody,
- DrawerContent,
- DrawerFooter,
- DrawerHeader,
- DrawerTitle,
- HStack,
- VStack,
-} from "@carbon/react";
-
-import { ValidatedForm } from "@carbon/form";
-import { useParams } from "@remix-run/react";
-import { useState } from "react";
-import type { z } from "zod";
-import {
- CustomFormFields,
- Employee,
- Hidden,
- Number,
- Select,
- Submit,
-} from "~/components/Form";
-import { usePermissions } from "~/hooks";
-import { AbilityEmployeeStatus, type Ability } from "../../types";
-
-import { path } from "~/utils/path";
-import { employeeAbilityValidator } from "../../resources.models";
-
-type EmployeeAbilityFormProps = {
- ability?: Ability;
- initialValues: z.infer<typeof employeeAbilityValidator>;
- weeks: number;
- onClose: () => void;
-};
-
-const defaultPercent = 0.5;
-
-const EmployeeAbilityForm = ({
- ability,
- initialValues,
- weeks,
- onClose,
-}: EmployeeAbilityFormProps) => {
- const { id } = useParams();
- const permissions = usePermissions();
- const isEditing = !!initialValues.employeeId;
- const isDisabled = isEditing
- ? !permissions.can("update", "resources")
- : !permissions.can("create", "resources");
-
- const days = (percent: number) => weeks * 5 * percent;
- const [trainingDays, setTrainingDays] = useState(
- days(initialValues.trainingPercent ?? defaultPercent)
- );
- const updateTrainingDays = (percent: number) => {
- setTrainingDays(days(percent));
- };
-
- const [inProgress, setInProgress] = useState(
- initialValues?.trainingStatus === AbilityEmployeeStatus.InProgress
- );
-
- if (!ability) return null;
-
- return (
- <Drawer
- open
- onOpenChange={(open) => {
- if (!open) onClose();
- }}
- >
- <DrawerContent>
- <ValidatedForm
- validator={employeeAbilityValidator}
- method="post"
- action={
- isEditing
- ? path.to.employeeAbility(ability.id, id!)
- : path.to.newEmployeeAbility(ability.id)
- }
- defaultValues={initialValues}
- className="flex flex-col h-full"
- >
- <DrawerHeader>
- <DrawerTitle>{isEditing ? "Edit" : "New"} Employee</DrawerTitle>
- </DrawerHeader>
- <DrawerBody>
- <VStack spacing={4}>
- <Employee
- name="employeeId"
- label="Employee"
- isReadOnly={isEditing}
- />
- <Select
- name="trainingStatus"
- label="Training Status"
- onChange={(value) => {
- setInProgress(
- value?.value === AbilityEmployeeStatus.InProgress
- );
- }}
- options={[
- {
- value: AbilityEmployeeStatus.NotStarted,
- label: "Not Started",
- },
- {
- value: AbilityEmployeeStatus.InProgress,
- label: "In Progress",
- },
- {
- value: AbilityEmployeeStatus.Complete,
- label: "Complete",
- },
- ]}
- />
- {inProgress && (
- <>
- <Number
- name="trainingPercent"
- label="Training Percent"
- onChange={(value) => updateTrainingDays(value)}
- defaultValue={defaultPercent}
- formatOptions={{ style: "percent" }}
- minValue={0}
- maxValue={1}
- />
- <Hidden name="trainingDays" value={trainingDays} />
- </>
- )}
- <CustomFormFields table="employeeAbility" />
- </VStack>
- </DrawerBody>
- <DrawerFooter>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </DrawerFooter>
- </ValidatedForm>
- </DrawerContent>
- </Drawer>
- );
-};
-
-export default EmployeeAbilityForm;
diff --git a/apps/erp/app/modules/resources/ui/Abilities/index.ts b/apps/erp/app/modules/resources/ui/Abilities/index.ts
deleted file mode 100644
index b2fcd86088..0000000000
--- a/apps/erp/app/modules/resources/ui/Abilities/index.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import AbilitiesTable from "./AbilitiesTable";
-import AbilityEmployeesTable from "./AbilityEmployeesTable";
-import AbilityForm from "./AbilityForm";
-import EmployeeAbilityForm from "./EmployeeAbilityForm";
-
-export {
- AbilitiesTable,
- AbilityEmployeesTable,
- AbilityForm,
- EmployeeAbilityForm,
-};
diff --git a/apps/erp/app/modules/resources/ui/Contractors/ContractorForm.tsx b/apps/erp/app/modules/resources/ui/Contractors/ContractorForm.tsx
index f28d8bf60b..4eb950a2c1 100644
--- a/apps/erp/app/modules/resources/ui/Contractors/ContractorForm.tsx
+++ b/apps/erp/app/modules/resources/ui/Contractors/ContractorForm.tsx
@@ -16,7 +16,6 @@ import { useLocation, useNavigate } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
import {
- Abilities,
CustomFormFields,
Number,
Submit,
@@ -85,7 +84,7 @@ const ContractorForm = ({ initialValues }: ContractorFormProps) => {
supplier={supplier ?? undefined}
isReadOnly={isEditing}
/>
- <Abilities name="abilities" label="Abilities" />
+ {/* <Abilities name="abilities" label="Abilities" /> */}
<Number
name="hoursPerWeek"
label="Hours per Week"
diff --git a/apps/erp/app/modules/resources/ui/Contractors/ContractorsTable.tsx b/apps/erp/app/modules/resources/ui/Contractors/ContractorsTable.tsx
index dd1bf43221..785897f09b 100644
--- a/apps/erp/app/modules/resources/ui/Contractors/ContractorsTable.tsx
+++ b/apps/erp/app/modules/resources/ui/Contractors/ContractorsTable.tsx
@@ -4,160 +4,157 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { LuPencil, LuTrash } from "react-icons/lu";
import { Hyperlink, New, SupplierAvatar, Table } from "~/components";
-import { Enumerable } from "~/components/Enumerable";
import { usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
-import type { Ability, Contractor } from "~/modules/resources";
+import type { Contractor } from "~/modules/resources";
import { useSuppliers } from "~/stores";
import { path } from "~/utils/path";
type ContractorsTableProps = {
data: Contractor[];
count: number;
- abilities: Partial<Ability>[];
+ // abilities: Partial<Ability>[];
};
-const ContractorsTable = memo(
- ({ data, count, abilities }: ContractorsTableProps) => {
- const navigate = useNavigate();
- const permissions = usePermissions();
- const [params] = useUrlParams();
+const ContractorsTable = memo(({ data, count }: ContractorsTableProps) => {
+ const navigate = useNavigate();
+ const permissions = usePermissions();
+ const [params] = useUrlParams();
- const [suppliers] = useSuppliers();
+ const [suppliers] = useSuppliers();
- const customColumns = useCustomColumns<Contractor>("contractor");
- const columns = useMemo<ColumnDef<Contractor>[]>(() => {
- const defaultColumns: ColumnDef<Contractor>[] = [
- {
- header: "Contractor",
- cell: ({ row }) => (
- <HStack>
- <Avatar
- size="sm"
- name={row.original.fullName ?? row.original.email ?? "Unknown"}
- />
- <Hyperlink
- to={`${path.to.contractor(
- row.original.supplierContactId!
- )}?${params.toString()}`}
- >
- {row.original.fullName ?? row.original.email ?? "Unknown"}
- </Hyperlink>
- </HStack>
- ),
- },
- {
- id: "supplierId",
- header: "Supplier",
- cell: ({ row }) => (
- <SupplierAvatar supplierId={row.original.supplierId} />
- ),
- meta: {
- filter: {
- type: "static",
- options: suppliers.map((supplier) => ({
- value: supplier.id,
- label: supplier.name,
- })),
- },
+ const customColumns = useCustomColumns<Contractor>("contractor");
+ const columns = useMemo<ColumnDef<Contractor>[]>(() => {
+ const defaultColumns: ColumnDef<Contractor>[] = [
+ {
+ header: "Contractor",
+ cell: ({ row }) => (
+ <HStack>
+ <Avatar
+ size="sm"
+ name={row.original.fullName ?? row.original.email ?? "Unknown"}
+ />
+ <Hyperlink
+ to={`${path.to.contractor(
+ row.original.supplierContactId!
+ )}?${params.toString()}`}
+ >
+ {row.original.fullName ?? row.original.email ?? "Unknown"}
+ </Hyperlink>
+ </HStack>
+ ),
+ },
+ {
+ id: "supplierId",
+ header: "Supplier",
+ cell: ({ row }) => (
+ <SupplierAvatar supplierId={row.original.supplierId} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: suppliers.map((supplier) => ({
+ value: supplier.id,
+ label: supplier.name,
+ })),
},
},
+ },
- {
- id: "abilityIds",
- header: "Abilities",
- cell: ({ row }) => {
- if (!row.original.abilityIds) {
- return null;
- } else if (
- row.original.abilityIds &&
- row.original.abilityIds.length === 1
- ) {
- const ability = abilities.find(
- (a) => a.id === row.original.abilityIds![0]
- );
- return <Enumerable value={ability?.name ?? ""} />;
- } else if (
- row.original.abilityIds &&
- row.original.abilityIds.length > 1
- ) {
- return "Multiple Abilities";
- }
- },
- meta: {
- filter: {
- type: "static",
- options: abilities.map((a) => ({
- value: a.id!,
- label: <Enumerable value={a.name!} />,
- })),
- isArray: true,
- },
- pluralHeader: "Abilities",
- },
- },
- {
- accessorKey: "hoursPerWeek",
- header: "Hours per Week",
- cell: (item) => item.getValue(),
- },
- ];
+ // {
+ // id: "abilityIds",
+ // header: "Abilities",
+ // cell: ({ row }) => {
+ // if (!row.original.abilityIds) {
+ // return null;
+ // } else if (
+ // row.original.abilityIds &&
+ // row.original.abilityIds.length === 1
+ // ) {
+ // const ability = abilities.find(
+ // (a) => a.id === row.original.abilityIds![0]
+ // );
+ // return <Enumerable value={ability?.name ?? ""} />;
+ // } else if (
+ // row.original.abilityIds &&
+ // row.original.abilityIds.length > 1
+ // ) {
+ // return "Multiple Abilities";
+ // }
+ // },
+ // meta: {
+ // filter: {
+ // type: "static",
+ // options: abilities.map((a) => ({
+ // value: a.id!,
+ // label: <Enumerable value={a.name!} />,
+ // })),
+ // isArray: true,
+ // },
+ // pluralHeader: "Abilities",
+ // },
+ // },
+ {
+ accessorKey: "hoursPerWeek",
+ header: "Hours per Week",
+ cell: (item) => item.getValue(),
+ },
+ ];
- return [...defaultColumns, ...customColumns];
- }, [suppliers, abilities, customColumns, params]);
+ return [...defaultColumns, ...customColumns];
+ }, [suppliers, customColumns, params]);
- const renderContextMenu = useCallback(
- (row: Contractor) => {
- return (
- <>
- <MenuItem
- onClick={() => {
- navigate(
- `${path.to.contractor(
- row.supplierContactId!
- )}?${params.toString()}`
- );
- }}
- >
- <MenuIcon icon={<LuPencil />} />
- Edit Contractor
- </MenuItem>
- <MenuItem
- destructive
- disabled={!permissions.can("delete", "resources")}
- onClick={() => {
- navigate(
- `${path.to.deleteContractor(
- row.supplierContactId!
- )}?${params.toString()}`
- );
- }}
- >
- <MenuIcon icon={<LuTrash />} />
- Delete Contractor
- </MenuItem>
- </>
- );
- },
- [navigate, params, permissions]
- );
+ const renderContextMenu = useCallback(
+ (row: Contractor) => {
+ return (
+ <>
+ <MenuItem
+ onClick={() => {
+ navigate(
+ `${path.to.contractor(
+ row.supplierContactId!
+ )}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuPencil />} />
+ Edit Contractor
+ </MenuItem>
+ <MenuItem
+ destructive
+ disabled={!permissions.can("delete", "resources")}
+ onClick={() => {
+ navigate(
+ `${path.to.deleteContractor(
+ row.supplierContactId!
+ )}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuTrash />} />
+ Delete Contractor
+ </MenuItem>
+ </>
+ );
+ },
+ [navigate, params, permissions]
+ );
- return (
- <Table<Contractor>
- data={data}
- count={count}
- columns={columns}
- primaryAction={
- permissions.can("create", "resources") && (
- <New label="Contractor" to={`new?${params.toString()}`} />
- )
- }
- renderContextMenu={renderContextMenu}
- title="Contractors"
- />
- );
- }
-);
+ return (
+ <Table<Contractor>
+ data={data}
+ count={count}
+ columns={columns}
+ primaryAction={
+ permissions.can("create", "resources") && (
+ <New label="Contractor" to={`new?${params.toString()}`} />
+ )
+ }
+ renderContextMenu={renderContextMenu}
+ title="Contractors"
+ />
+ );
+});
ContractorsTable.displayName = "ContractorsTable";
export default ContractorsTable;
diff --git a/apps/erp/app/modules/resources/ui/Partners/PartnerForm.tsx b/apps/erp/app/modules/resources/ui/Partners/PartnerForm.tsx
index 82b0e80a52..3d3500a288 100644
--- a/apps/erp/app/modules/resources/ui/Partners/PartnerForm.tsx
+++ b/apps/erp/app/modules/resources/ui/Partners/PartnerForm.tsx
@@ -1,114 +1,115 @@
-import { ValidatedForm } from "@carbon/form";
-import {
- Button,
- Drawer,
- DrawerBody,
- DrawerContent,
- DrawerDescription,
- DrawerFooter,
- DrawerHeader,
- DrawerTitle,
- HStack,
- VStack,
-} from "@carbon/react";
-import { useNavigate } from "@remix-run/react";
-import { useState } from "react";
+// import { ValidatedForm } from "@carbon/form";
+// import {
+// Button,
+// Drawer,
+// DrawerBody,
+// DrawerContent,
+// DrawerDescription,
+// DrawerFooter,
+// DrawerHeader,
+// DrawerTitle,
+// HStack,
+// VStack,
+// } from "@carbon/react";
+// import { useNavigate } from "@remix-run/react";
+// import { useState } from "react";
import type { z } from "zod";
-import {
- Ability,
- CustomFormFields,
- Number,
- Submit,
- Supplier,
- SupplierLocation,
-} from "~/components/Form";
-import { usePermissions } from "~/hooks";
-import { partnerValidator } from "~/modules/resources";
-import { path } from "~/utils/path";
+// import {
+// CustomFormFields,
+// Number,
+// Submit,
+// Supplier,
+// SupplierLocation,
+// } from "~/components/Form";
+// import { usePermissions } from "~/hooks";
+import type { partnerValidator } from "~/modules/resources";
+// import { path } from "~/utils/path";
type PartnerFormProps = {
initialValues: z.infer<typeof partnerValidator>;
};
const PartnerForm = ({ initialValues }: PartnerFormProps) => {
- const permissions = usePermissions();
- const navigate = useNavigate();
- const onClose = () => navigate(-1);
- const [supplier, setSupplier] = useState<string | null>(
- initialValues.supplierId ?? null
- );
+ // const permissions = usePermissions();
+ // const navigate = useNavigate();
+ // const onClose = () => navigate(-1);
+ // const [supplier, setSupplier] = useState<string | null>(
+ // initialValues.supplierId ?? null
+ // );
- const isEditing = initialValues.id !== "";
- const isDisabled = isEditing
- ? !permissions.can("update", "resources")
- : !permissions.can("create", "resources");
+ // const isEditing = initialValues.id !== "";
+ // const isDisabled = isEditing
+ // ? !permissions.can("update", "resources")
+ // : !permissions.can("create", "resources");
- const onSupplierChange = (newValue: { value: string } | null) => {
- if (newValue) setSupplier(newValue?.value ?? null);
- };
+ // const onSupplierChange = (newValue: { value: string } | null) => {
+ // if (newValue) setSupplier(newValue?.value ?? null);
+ // };
- return (
- <Drawer
- open
- onOpenChange={(open) => {
- if (!open) onClose();
- }}
- >
- <DrawerContent>
- <ValidatedForm
- validator={partnerValidator}
- method="post"
- action={
- isEditing
- ? path.to.partner(initialValues.id, initialValues.abilityId)
- : path.to.newPartner
- }
- defaultValues={initialValues}
- className="flex flex-col h-full"
- >
- <DrawerHeader>
- <DrawerTitle>{isEditing ? "Edit" : "New"} Partner</DrawerTitle>
- <DrawerDescription>
- A partner is combination of a supplier location and and an ability
- with a certain amount of time available
- </DrawerDescription>
- </DrawerHeader>
- <DrawerBody>
- <VStack spacing={4}>
- <Supplier
- name="supplierId"
- label="Supplier"
- disabled={isEditing}
- onChange={onSupplierChange}
- />
- <SupplierLocation
- name="id"
- supplier={supplier ?? undefined}
- disabled={isEditing}
- />
- <Ability name="abilityId" label="Ability" />
- <Number
- name="hoursPerWeek"
- label="Hours per Week"
- helperText="The number of hours per week the supplier is available to work."
- minValue={0}
- maxValue={10000}
- />
- <CustomFormFields table="partner" />
- </VStack>
- </DrawerBody>
- <DrawerFooter>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </DrawerFooter>
- </ValidatedForm>
- </DrawerContent>
- </Drawer>
- );
+ return null;
+
+ // return (
+ // <Drawer
+ // open
+ // onOpenChange={(open) => {
+ // if (!open) onClose();
+ // }}
+ // >
+ // <DrawerContent>
+ // <ValidatedForm
+ // validator={partnerValidator}
+ // method="post"
+ // action={
+ // isEditing
+ // ? path.to.partner(initialValues.id, initialValues.abilityId)
+ // : path.to.newPartner
+ // }
+ // defaultValues={initialValues}
+ // className="flex flex-col h-full"
+ // >
+ // <DrawerHeader>
+ // <DrawerTitle>{isEditing ? "Edit" : "New"} Partner</DrawerTitle>
+ // <DrawerDescription>
+ // A partner is combination of a supplier location and and an ability
+ // with a certain amount of time available
+ // </DrawerDescription>
+ // </DrawerHeader>
+ // <DrawerBody>
+ // <VStack spacing={4}>
+ // <Supplier
+ // name="supplierId"
+ // label="Supplier"
+ // disabled={isEditing}
+ // onChange={onSupplierChange}
+ // />
+ // <SupplierLocation
+ // name="id"
+ // supplier={supplier ?? undefined}
+ // disabled={isEditing}
+ // />
+ // {/* <Ability name="abilityId" label="Ability" /> */}
+ // <Number
+ // name="hoursPerWeek"
+ // label="Hours per Week"
+ // helperText="The number of hours per week the supplier is available to work."
+ // minValue={0}
+ // maxValue={10000}
+ // />
+ // <CustomFormFields table="partner" />
+ // </VStack>
+ // </DrawerBody>
+ // <DrawerFooter>
+ // <HStack>
+ // <Submit isDisabled={isDisabled}>Save</Submit>
+ // <Button size="md" variant="solid" onClick={onClose}>
+ // Cancel
+ // </Button>
+ // </HStack>
+ // </DrawerFooter>
+ // </ValidatedForm>
+ // </DrawerContent>
+ // </Drawer>
+ // );
};
export default PartnerForm;
diff --git a/apps/erp/app/modules/resources/ui/Partners/PartnersTable.tsx b/apps/erp/app/modules/resources/ui/Partners/PartnersTable.tsx
index f33e98884e..f006585965 100644
--- a/apps/erp/app/modules/resources/ui/Partners/PartnersTable.tsx
+++ b/apps/erp/app/modules/resources/ui/Partners/PartnersTable.tsx
@@ -4,20 +4,19 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { LuPencil, LuTrash } from "react-icons/lu";
import { Hyperlink, New, Table } from "~/components";
-import { Enumerable } from "~/components/Enumerable";
import { usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
-import type { Ability, Partner } from "~/modules/resources";
+import type { Partner } from "~/modules/resources";
import { useSuppliers } from "~/stores";
import { path } from "~/utils/path";
type PartnersTableProps = {
data: Partner[];
count: number;
- abilities: Partial<Ability>[];
+ // abilities: Partial<Ability>[];
};
-const PartnersTable = memo(({ data, count, abilities }: PartnersTableProps) => {
+const PartnersTable = memo(({ data, count }: PartnersTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
const [params] = useUrlParams();
@@ -57,20 +56,20 @@ const PartnersTable = memo(({ data, count, abilities }: PartnersTableProps) => {
header: "Location",
cell: ({ row }) => `${row.original.city}, ${row.original.state}`,
},
- {
- accessorKey: "abilityName",
- header: "Ability",
- cell: (item) => <Enumerable value={item.getValue<string>()} />,
- meta: {
- filter: {
- type: "static",
- options: abilities.map((ability) => ({
- value: ability.name!,
- label: <Enumerable value={ability.name!} />,
- })),
- },
- },
- },
+ // {
+ // accessorKey: "abilityName",
+ // header: "Ability",
+ // cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ // meta: {
+ // filter: {
+ // type: "static",
+ // options: abilities.map((ability) => ({
+ // value: ability.name!,
+ // label: <Enumerable value={ability.name!} />,
+ // })),
+ // },
+ // },
+ // },
{
accessorKey: "hoursPerWeek",
header: "Hours per Week",
@@ -79,7 +78,7 @@ const PartnersTable = memo(({ data, count, abilities }: PartnersTableProps) => {
];
return [...defaultColumns, ...customColumns];
- }, [params, customColumns, suppliers, abilities]);
+ }, [params, customColumns, suppliers]);
const renderContextMenu = useCallback(
(row: Partner) => {
diff --git a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
index 6da5e455c2..6e2f436ebd 100644
--- a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
+++ b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCenterForm.tsx
@@ -17,7 +17,7 @@ import type { PostgrestResponse } from "@supabase/supabase-js";
import { useEffect } from "react";
import type { z } from "zod";
import {
- Ability,
+ // Ability,
CustomFormFields,
Hidden,
Input,
@@ -138,11 +138,11 @@ const WorkCenterForm = ({
label="Default Unit"
value={initialValues.defaultStandardFactor}
/>
- <Ability
+ {/* <Ability
name="requiredAbilityId"
label="Required Ability"
isClearable
- />
+ /> */}
<CustomFormFields table="workCenter" />
</VStack>
</ModalDrawerBody>
diff --git a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
index a294222ec2..968011cb71 100644
--- a/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
+++ b/apps/erp/app/modules/resources/ui/WorkCenters/WorkCentersTable.tsx
@@ -5,7 +5,6 @@ import { memo, useCallback, useMemo, useState } from "react";
import {
LuAlignLeft,
LuBuilding2,
- LuCircleCheck,
LuCog,
LuDollarSign,
LuPencil,
@@ -84,13 +83,6 @@ const WorkCentersTable = memo(
</HStack>
</Hyperlink>
)}
-
- {row.original.requiredAbilityId && (
- <LuCircleCheck
- className="text-emerald-500"
- title="Requires ability"
- />
- )}
</HStack>
),
meta: {
diff --git a/apps/erp/app/modules/resources/ui/index.ts b/apps/erp/app/modules/resources/ui/index.ts
index 28734dd751..bcc103eb6d 100644
--- a/apps/erp/app/modules/resources/ui/index.ts
+++ b/apps/erp/app/modules/resources/ui/index.ts
@@ -1,6 +1,5 @@
import useResourcesSubmodules from "./useResourcesSubmodules";
-export * from "./Abilities";
export * from "./Contractors";
export * from "./Locations";
export * from "./Partners";
diff --git a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
index 0bf671f60e..ae3ec20223 100644
--- a/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
+++ b/apps/erp/app/modules/resources/ui/useResourcesSubmodules.tsx
@@ -1,4 +1,4 @@
-import { LuHammer, LuMapPin } from "react-icons/lu";
+import { LuMapPin } from "react-icons/lu";
import { TbRoute } from "react-icons/tb";
import { useSavedViews } from "~/hooks/useSavedViews";
import type { RouteGroup } from "~/types";
@@ -8,12 +8,6 @@ const resourcesRoutes: RouteGroup[] = [
{
name: "Manage",
routes: [
- {
- name: "Abilities",
- to: path.to.abilities,
- icon: <LuHammer />,
- table: "ability",
- },
{
name: "Locations",
to: path.to.locations,
diff --git a/apps/erp/app/routes/x+/resources+/abilities.delete.$abilityId.tsx b/apps/erp/app/routes/x+/resources+/abilities.delete.$abilityId.tsx
deleted file mode 100644
index a15357f1fc..0000000000
--- a/apps/erp/app/routes/x+/resources+/abilities.delete.$abilityId.tsx
+++ /dev/null
@@ -1,91 +0,0 @@
-import { error, notFound, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import type { ClientActionFunctionArgs } from "@remix-run/react";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import { ConfirmDelete } from "~/components/Modals";
-import { deleteAbility, getAbility } from "~/modules/resources";
-import { path } from "~/utils/path";
-import { abilitiesQuery, getCompanyId } from "~/utils/react-query";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "resources",
- role: "employee",
- });
-
- const { abilityId } = params;
- if (!abilityId) throw notFound("abilityId not found");
-
- const ability = await getAbility(client, abilityId);
- if (ability.error) {
- throw redirect(
- path.to.abilities,
- await flash(request, error(ability.error, "Failed to get ability"))
- );
- }
-
- return json({
- ability: ability.data,
- });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "resources",
- });
-
- const { abilityId } = params;
- if (!abilityId) {
- throw redirect(
- path.to.abilities,
- await flash(request, error(params, "Failed to get ability id"))
- );
- }
-
- const { error: deleteAbilityError } = await deleteAbility(client, abilityId);
- if (deleteAbilityError) {
- throw redirect(
- path.to.abilities,
- await flash(
- request,
- error(deleteAbilityError, "Failed to delete ability")
- )
- );
- }
-
- throw redirect(
- path.to.abilities,
- await flash(request, success("Successfully deleted employee type"))
- );
-}
-
-export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.clientCache?.setQueryData(
- abilitiesQuery(getCompanyId()).queryKey,
- null
- );
- return await serverAction();
-}
-
-export default function DeleteEmployeeTypeRoute() {
- const { abilityId } = useParams();
- const { ability } = useLoaderData<typeof loader>();
- const navigate = useNavigate();
-
- if (!ability) return null;
- if (!abilityId) throw notFound("abilityId not found");
-
- const onCancel = () => navigate(path.to.abilities);
-
- return (
- <ConfirmDelete
- action={path.to.deleteAbility(abilityId)}
- name={ability.name}
- text={`Are you sure you want to delete the ability: ${ability.name}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/erp/app/routes/x+/resources+/abilities.new.tsx b/apps/erp/app/routes/x+/resources+/abilities.new.tsx
deleted file mode 100644
index 6a48182391..0000000000
--- a/apps/erp/app/routes/x+/resources+/abilities.new.tsx
+++ /dev/null
@@ -1,131 +0,0 @@
-import { assertIsPost, error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { validationError, validator } from "@carbon/form";
-import type { ClientActionFunctionArgs } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import {
- AbilityForm,
- abilityValidator,
- deleteAbility,
- insertAbility,
- insertEmployeeAbilities,
-} from "~/modules/resources";
-import { path } from "~/utils/path";
-import { abilitiesQuery, getCompanyId } from "~/utils/react-query";
-
-function makeCurve(startingPoint: number, weeks: number) {
- return {
- data: [
- {
- week: 0,
- value: startingPoint,
- },
- {
- week: weeks / 4,
- value: (100 - startingPoint) * 0.5 + startingPoint,
- },
- {
- week: weeks / 2,
- value: 100 - (100 - startingPoint) * 0.25,
- },
- {
- week: weeks,
- value: 100,
- },
- ],
- };
-}
-
-export async function action({ request }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "resources",
- });
-
- const validation = await validator(abilityValidator).validate(
- await request.formData()
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { name, startingPoint, shadowWeeks, weeks, employees } =
- validation.data;
-
- const createAbility = await insertAbility(client, {
- name,
- curve: makeCurve(startingPoint, weeks),
- shadowWeeks,
- companyId,
- createdBy: userId,
- });
- if (createAbility.error) {
- return json(
- {},
- await flash(
- request,
- error(createAbility.error, "Failed to insert ability")
- )
- );
- }
-
- const abilityId = createAbility.data?.id;
- if (!abilityId) {
- return json(
- {},
- await flash(request, error(createAbility, "Failed to insert ability"))
- );
- }
-
- if (employees) {
- const createEmployeeAbilities = await insertEmployeeAbilities(
- client,
- abilityId,
- employees,
- companyId
- );
-
- if (createEmployeeAbilities.error) {
- console.error(createEmployeeAbilities.error);
- await deleteAbility(client, abilityId, true);
- return json(
- {},
- await flash(
- request,
- error(
- createEmployeeAbilities.error,
- "Failed to insert ability members"
- )
- )
- );
- }
- }
-
- throw redirect(
- path.to.abilities,
- await flash(request, success(`Ability created`))
- );
-}
-
-export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.clientCache?.setQueryData(
- abilitiesQuery(getCompanyId()).queryKey,
- null
- );
- return await serverAction();
-}
-
-export default function NewAbilityRoute() {
- const initialValues = {
- name: "",
- startingPoint: 85,
- shadowWeeks: 0,
- weeks: 4,
- employees: [],
- };
-
- return <AbilityForm initialValues={initialValues} />;
-}
diff --git a/apps/erp/app/routes/x+/resources+/abilities.tsx b/apps/erp/app/routes/x+/resources+/abilities.tsx
deleted file mode 100644
index 025c750ac9..0000000000
--- a/apps/erp/app/routes/x+/resources+/abilities.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import { error } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { VStack } from "@carbon/react";
-import { Outlet, useLoaderData } from "@remix-run/react";
-import type { LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import { AbilitiesTable, getAbilities } from "~/modules/resources";
-import type { Handle } from "~/utils/handle";
-import { path } from "~/utils/path";
-import { getGenericQueryFilters } from "~/utils/query";
-
-export const handle: Handle = {
- breadcrumb: "Abilities",
- to: path.to.abilities,
-};
-
-export async function loader({ request }: LoaderFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
- view: "resources",
- role: "employee",
- bypassRls: true,
- });
-
- const url = new URL(request.url);
- const searchParams = new URLSearchParams(url.search);
- const search = searchParams.get("search");
- const { limit, offset, sorts, filters } =
- getGenericQueryFilters(searchParams);
-
- const abilities = await getAbilities(client, companyId, {
- search,
- limit,
- offset,
- sorts,
- filters,
- });
-
- if (abilities.error) {
- throw redirect(
- path.to.resources,
- await flash(request, error(abilities.error, "Failed to load abilities"))
- );
- }
-
- return json({
- abilities: abilities.data ?? [],
- count: abilities.count ?? 0,
- });
-}
-
-export default function AbilitiesRoute() {
- const { abilities, count } = useLoaderData<typeof loader>();
-
- return (
- <VStack spacing={0} className="h-full">
- <AbilitiesTable data={abilities} count={count} />
- <Outlet />
- </VStack>
- );
-}
diff --git a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.$id.tsx b/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.$id.tsx
deleted file mode 100644
index f5b788551f..0000000000
--- a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.$id.tsx
+++ /dev/null
@@ -1,129 +0,0 @@
-import { error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { validationError, validator } from "@carbon/form";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
-import { useRouteData } from "~/hooks";
-import type { Ability } from "~/modules/resources";
-import {
- AbilityEmployeeStatus,
- EmployeeAbilityForm,
- employeeAbilityValidator,
- getEmployeeAbility,
- getTrainingStatus,
- upsertEmployeeAbility,
-} from "~/modules/resources";
-import { path } from "~/utils/path";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "resources",
- });
-
- // get the abilityId and id from the params
- const { abilityId, id } = params;
- if (!abilityId) {
- throw new Error("Ability ID not found");
- }
-
- if (!id) {
- throw new Error("Employee ID not found");
- }
-
- const employeeAbility = await getEmployeeAbility(client, abilityId, id);
- if (employeeAbility.error) {
- redirect(
- path.to.abilities,
- await flash(
- request,
- error(employeeAbility.error, "Failed to get employee ability")
- )
- );
- }
-
- return { employeeAbility: employeeAbility.data };
-}
-
-export async function action({ params, request }: ActionFunctionArgs) {
- const { abilityId, id } = params;
- if (!abilityId) throw new Error("abilityId is not found");
- if (!id) throw new Error("id is not found");
-
- const { client, companyId } = await requirePermissions(request, {
- create: "resources",
- });
-
- const validation = await validator(employeeAbilityValidator).validate(
- await request.formData()
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { employeeId, trainingStatus, trainingDays } = validation.data;
-
- const updateEmployeeAbility = await upsertEmployeeAbility(client, {
- id,
- employeeId,
- abilityId,
- trainingCompleted: trainingStatus === AbilityEmployeeStatus.Complete,
- trainingDays: trainingDays || 0,
- companyId,
- });
-
- if (updateEmployeeAbility.error) {
- throw redirect(
- path.to.ability(abilityId),
- await flash(
- request,
- error(
- updateEmployeeAbility.error,
- "Failed to insert new employee ability"
- )
- )
- );
- }
-
- throw redirect(
- path.to.ability(abilityId),
- await flash(request, success("Employee ability updated"))
- );
-}
-
-export default function EmployeeAbilityRoute() {
- const navigate = useNavigate();
- const { abilityId } = useParams();
- if (!abilityId) throw new Error("abilityId is not found");
- const { employeeAbility } = useLoaderData<typeof loader>();
- const routeData = useRouteData<{
- ability: Ability;
- weeks: number;
- }>(path.to.ability(abilityId));
-
- const initialValues = {
- employeeId: employeeAbility?.employeeId ?? "",
- trainingStatus: getTrainingStatus(employeeAbility) ?? "",
- trainingPercent: getTrainingPercent(
- employeeAbility?.trainingDays,
- routeData?.weeks
- ),
- };
-
- return (
- <EmployeeAbilityForm
- key={`${initialValues.employeeId}${abilityId}`}
- ability={routeData?.ability}
- initialValues={initialValues}
- weeks={routeData?.weeks ?? 4}
- onClose={() => navigate(-1)}
- />
- );
-}
-
-function getTrainingPercent(traniningDays?: number, weeks?: number) {
- if (!traniningDays || !weeks) return 0;
- return traniningDays / 5 / weeks;
-}
diff --git a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.delete.$id.tsx b/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.delete.$id.tsx
deleted file mode 100644
index e04c6a2d71..0000000000
--- a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.delete.$id.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import { error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { useNavigate, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
-import { ConfirmDelete } from "~/components/Modals";
-import { useRouteData } from "~/hooks";
-import type { Ability } from "~/modules/resources";
-import { deleteEmployeeAbility } from "~/modules/resources";
-import { usePeople } from "~/stores";
-import { path } from "~/utils/path";
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "resources",
- });
-
- const { abilityId, id } = params;
- if (!abilityId) throw new Error("No abilityId provided");
- if (!id) throw new Error("No id provided");
-
- const removeEmployeeAbility = await deleteEmployeeAbility(client, id);
- if (removeEmployeeAbility.error) {
- throw redirect(
- path.to.ability(abilityId),
- await flash(
- request,
- error(removeEmployeeAbility.error, "Failed to delete employee ability")
- )
- );
- }
-
- throw redirect(
- path.to.ability(abilityId),
- await flash(request, success("Successfully deleted employee ability"))
- );
-}
-
-export default function DeleteEmployeeAbilityRoute() {
- const navigate = useNavigate();
- const { abilityId, id } = useParams();
- const [people] = usePeople();
-
- if (!id) throw new Error("id is not found");
- if (!abilityId) throw new Error("abilityId is not found");
-
- const routeData = useRouteData<{
- ability: Ability;
- }>(path.to.ability(abilityId));
-
- if (!routeData?.ability) return null;
- if (!abilityId) throw new Error("abilityId is not found");
-
- const employee = Array.isArray(routeData?.ability.employeeAbility)
- ? routeData.ability.employeeAbility.find((ea) => ea.id === id)
- : undefined;
-
- const onCancel = () => navigate(path.to.ability(abilityId));
-
- const person = people?.find((p) => p.id === employee?.employeeId);
-
- const name = person ? person.name : "this employee";
- return (
- <ConfirmDelete
- action={path.to.deleteEmployeeAbility(abilityId, id)}
- name={name}
- text={`Are you sure you want remove delete ${name}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.new.tsx b/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.new.tsx
deleted file mode 100644
index 279ed83562..0000000000
--- a/apps/erp/app/routes/x+/resources+/ability.$abilityId.employee.new.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import { error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { validationError, validator } from "@carbon/form";
-import { useNavigate, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
-import { useRouteData } from "~/hooks";
-import type { Ability } from "~/modules/resources";
-import {
- AbilityEmployeeStatus,
- EmployeeAbilityForm,
- employeeAbilityValidator,
- upsertEmployeeAbility,
-} from "~/modules/resources";
-import { path } from "~/utils/path";
-
-export async function action({ params, request }: ActionFunctionArgs) {
- const { abilityId } = params;
- if (!abilityId) throw new Error("abilityId is not found");
-
- const { client, companyId } = await requirePermissions(request, {
- create: "resources",
- });
-
- const validation = await validator(employeeAbilityValidator).validate(
- await request.formData()
- );
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { employeeId, trainingStatus, trainingDays } = validation.data;
-
- const insertEmployeeAbility = await upsertEmployeeAbility(client, {
- employeeId,
- abilityId,
- trainingCompleted: trainingStatus === AbilityEmployeeStatus.Complete,
- trainingDays: trainingDays || 0,
- companyId,
- });
-
- if (insertEmployeeAbility.error) {
- throw redirect(
- path.to.ability(abilityId),
- await flash(
- request,
- error(
- insertEmployeeAbility.error,
- "Failed to insert new employee ability"
- )
- )
- );
- }
-
- throw redirect(
- path.to.ability(abilityId),
- await flash(request, success("Employee ability created"))
- );
-}
-
-export default function NewEmployeeAbilityRoute() {
- const { abilityId } = useParams();
- if (!abilityId) throw new Error("abilityId is not found");
-
- const navigate = useNavigate();
- const onClose = () => navigate(-1);
- const abilitiesRouteData = useRouteData<{
- ability: Ability;
- weeks: number;
- }>(path.to.ability(abilityId));
-
- if (!abilitiesRouteData?.ability) return null;
-
- return (
- <EmployeeAbilityForm
- initialValues={{
- employeeId: "",
- trainingStatus: "",
- }}
- ability={abilitiesRouteData?.ability}
- weeks={abilitiesRouteData.weeks}
- onClose={onClose}
- />
- );
-}
diff --git a/apps/erp/app/routes/x+/resources+/ability.$abilityId.tsx b/apps/erp/app/routes/x+/resources+/ability.$abilityId.tsx
deleted file mode 100644
index f0b13e8462..0000000000
--- a/apps/erp/app/routes/x+/resources+/ability.$abilityId.tsx
+++ /dev/null
@@ -1,295 +0,0 @@
-import { error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { ValidatedForm, validationError, validator } from "@carbon/form";
-import {
- HStack,
- Heading,
- IconButton,
- NumberDecrementStepper,
- NumberField,
- NumberIncrementStepper,
- NumberInput,
- NumberInputGroup,
- NumberInputStepper,
- useDisclosure,
-} from "@carbon/react";
-import type { ClientActionFunctionArgs } from "@remix-run/react";
-import { Outlet, useLoaderData, useNavigate } from "@remix-run/react";
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import { useState } from "react";
-import { IoMdClose } from "react-icons/io";
-import {
- LuChevronDown,
- LuChevronLeft,
- LuChevronUp,
- LuSquarePen,
-} from "react-icons/lu";
-import { Hidden, Input, Submit } from "~/components/Form";
-import type { AbilityDatum } from "~/modules/resources";
-import {
- AbilityEmployeesTable,
- abilityCurveValidator,
- abilityNameValidator,
- getAbility,
- updateAbility,
-} from "~/modules/resources";
-import type { Handle } from "~/utils/handle";
-import { path } from "~/utils/path";
-import { abilitiesQuery, getCompanyId } from "~/utils/react-query";
-
-export const handle: Handle = {
- breadcrumb: "Abilities",
- to: path.to.abilities,
-};
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "resources",
- });
-
- const { abilityId } = params;
- if (!abilityId) {
- throw redirect(
- path.to.abilities,
- await flash(request, error(null, "Ability ID not found"))
- );
- }
-
- const ability = await getAbility(client, abilityId);
- if (ability.error || !ability.data) {
- throw redirect(
- path.to.abilities,
- await flash(request, error(ability.error, "Failed to load ability"))
- );
- }
-
- return json({
- ability: ability.data,
- weeks:
- // @ts-ignore
- ability.data.curve?.data[ability.data.curve?.data.length - 1].week ?? 0,
- });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- update: "resources",
- });
-
- const { abilityId } = params;
- if (!abilityId) {
- throw new Error("Ability ID not found");
- }
-
- const formData = await request.formData();
-
- if (formData.get("intent") === "name") {
- const validation = await validator(abilityNameValidator).validate(formData);
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { name } = validation.data;
- const updateAbilityName = await updateAbility(client, abilityId, {
- name,
- });
- if (updateAbilityName.error) {
- throw redirect(
- path.to.ability(abilityId),
- await flash(
- request,
- error(updateAbilityName.error, "Failed to update ability name")
- )
- );
- }
- }
-
- if (formData.get("intent") === "curve") {
- const validation = await validator(abilityCurveValidator).validate(
- formData
- );
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { data, shadowWeeks } = validation.data;
- const updateAbilityCurve = await updateAbility(client, abilityId, {
- curve: {
- data: JSON.parse(data),
- },
- shadowWeeks,
- });
- if (updateAbilityCurve.error) {
- throw redirect(
- path.to.ability(abilityId),
- await flash(
- request,
- error(updateAbilityCurve.error, "Failed to update ability data")
- )
- );
- }
- }
-
- throw redirect(
- path.to.ability(abilityId),
- await flash(request, success("Ability updated"))
- );
-}
-
-export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.clientCache?.setQueryData(
- abilitiesQuery(getCompanyId()).queryKey,
- null
- );
- return await serverAction();
-}
-
-export default function AbilitiesRoute() {
- const { ability, weeks } = useLoaderData<typeof loader>();
- const navigate = useNavigate();
- const editingTitle = useDisclosure();
- const [data, setData] = useState<AbilityDatum[]>(
- // @ts-ignore
- ability.curve?.data ?? []
- );
- const [time, setTime] = useState<number>(weeks);
- const [controlledShadowWeeks, setControlledShadowWeeks] = useState<number>(
- ability.shadowWeeks ?? 0
- );
-
- const updateWeeks = (newWeeks: number) => {
- const scale = 1 + (newWeeks - time) / time;
- setData((prevData) =>
- prevData.map((datum) => ({
- ...datum,
- week: Math.round(datum.week * scale * 10) / 10,
- }))
- );
- setTime(newWeeks);
- };
-
- const updateShadowTime = (newShadowTime: number) => {
- setControlledShadowWeeks(newShadowTime);
- };
-
- return (
- <>
- <div className="bg-card w-full relative border-b">
- <HStack className="w-full justify-between p-4">
- {editingTitle.isOpen ? (
- <ValidatedForm
- validator={abilityNameValidator}
- method="post"
- action={path.to.ability(ability.id)}
- defaultValues={{
- name: ability.name,
- }}
- onSubmit={editingTitle.onClose}
- >
- <Hidden name="intent" value="name" />
- <HStack>
- <IconButton
- aria-label="Back"
- variant="ghost"
- icon={<LuChevronLeft />}
- onClick={() => navigate(path.to.abilities)}
- />
- <Input
- autoFocus
- name="name"
- className="text-xl font-bold border-none shadow-none"
- />
- <Submit>Save</Submit>
- <IconButton
- aria-label="Cancel"
- variant="ghost"
- icon={<IoMdClose />}
- onClick={editingTitle.onClose}
- />
- </HStack>
- </ValidatedForm>
- ) : (
- <HStack>
- <IconButton
- aria-label="Back"
- variant="ghost"
- icon={<LuChevronLeft />}
- onClick={() => navigate(path.to.abilities)}
- />
- <Heading size="h3">{ability.name}</Heading>
- <IconButton
- aria-label="Edit"
- variant="ghost"
- icon={<LuSquarePen />}
- onClick={editingTitle.onOpen}
- />
- </HStack>
- )}
-
- <HStack>
- <span className="text-sm">Weeks Shadowing:</span>
- <NumberField
- name="unitPrice"
- value={controlledShadowWeeks}
- onChange={updateShadowTime}
- minValue={0}
- maxValue={time}
- className="max-w-[100px]"
- >
- <NumberInputGroup className="relative">
- <NumberInput size="sm" />
- <NumberInputStepper>
- <NumberIncrementStepper>
- <LuChevronUp size="0.75em" strokeWidth="3" />
- </NumberIncrementStepper>
- <NumberDecrementStepper>
- <LuChevronDown size="0.75em" strokeWidth="3" />
- </NumberDecrementStepper>
- </NumberInputStepper>
- </NumberInputGroup>
- </NumberField>
-
- <span className="text-sm">Weeks to Learn:</span>
- <NumberField
- name="unitPrice"
- value={time}
- onChange={updateWeeks}
- minValue={1}
- className="max-w-[100px]"
- >
- <NumberInputGroup className="relative">
- <NumberInput size="sm" />
- <NumberInputStepper>
- <NumberIncrementStepper>
- <LuChevronUp size="0.75em" strokeWidth="3" />
- </NumberIncrementStepper>
- <NumberDecrementStepper>
- <LuChevronDown size="0.75em" strokeWidth="3" />
- </NumberDecrementStepper>
- </NumberInputStepper>
- </NumberInputGroup>
- </NumberField>
-
- <ValidatedForm
- validator={abilityCurveValidator}
- method="post"
- action={path.to.ability(ability.id)}
- >
- <Hidden name="intent" value="curve" />
- <Hidden name="data" value={JSON.stringify(data)} />
- <Hidden name="shadowWeeks" value={controlledShadowWeeks} />
- <Submit>Save</Submit>
- </ValidatedForm>
- </HStack>
- </HStack>
- </div>
- <AbilityEmployeesTable
- employees={ability.employeeAbility ?? []}
- weeks={weeks}
- />
- <Outlet />
- </>
- );
-}
diff --git a/apps/erp/app/routes/x+/resources+/partners.tsx b/apps/erp/app/routes/x+/resources+/partners.tsx
index 04d47a8a6e..e93a89d3d1 100644
--- a/apps/erp/app/routes/x+/resources+/partners.tsx
+++ b/apps/erp/app/routes/x+/resources+/partners.tsx
@@ -32,7 +32,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
- const [partners, abilities] = await Promise.all([
+ const [partners] = await Promise.all([
getPartners(client, companyId, {
search,
limit,
@@ -52,17 +52,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
partners: partners.data ?? [],
- abilities: abilities.data ?? [],
count: partners.count ?? 0,
});
}
export default function Route() {
- const { partners, abilities, count } = useLoaderData<typeof loader>();
+ const { partners, count } = useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full">
- <PartnersTable data={partners} count={count} abilities={abilities} />
+ <PartnersTable data={partners} count={count} />
<Outlet />
</VStack>
);