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: image upload for work instructions

Brad Barbind4b8caf06d8f
diff --git a/apps/carbon/app/components/Form/StandardFactor.tsx b/apps/carbon/app/components/Form/StandardFactor.tsx
index 0427bc08a9..c79130b312 100644
--- a/apps/carbon/app/components/Form/StandardFactor.tsx
+++ b/apps/carbon/app/components/Form/StandardFactor.tsx
@@ -1,12 +1,12 @@
import { standardFactorType } from "~/modules/shared";
-import type { SelectProps } from "./Select";
-import Select from "./Select";
+import type { SelectProps } from "./SelectControlled";
+import SelectControlled from "./SelectControlled";
export type StandardFactorSelectProps = Omit<SelectProps, "options">;
const StandardFactor = (props: StandardFactorSelectProps) => {
return (
- <Select
+ <SelectControlled
{...props}
options={standardFactorType.map((t) => ({ value: t, label: t }))}
/>
diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.ts
index 4fbd189894..1bb0d659a1 100644
--- a/apps/carbon/app/modules/items/items.models.ts
+++ b/apps/carbon/app/modules/items/items.models.ts
@@ -13,6 +13,7 @@ export const defaultWorkInstruction = {
{ type: "paragraph" },
],
};
+
export const itemInventoryTypes = ["Inventory", "Non-Inventory"] as const;
export const partReplenishmentSystems = [
"Buy",
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index 612844ae2e..6d42ea314c 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -89,7 +89,10 @@ const initialMethodOperation: Omit<Operation, "makeMethodId" | "order"> = {
const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
const { supabase } = useSupabase();
const sortOrderFetcher = useFetcher();
- const { id: userId } = useUser();
+ const {
+ id: userId,
+ company: { id: companyId },
+ } = useUser();
const [items, setItems] = useState<ItemWithData[]>(
makeItems(operations ?? [])
@@ -218,6 +221,25 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
.eq("methodOperationId", selectedItemId!);
}, 1000);
+ const onUploadImage = async (file: File) => {
+ const fileName = `${companyId}/parts/${selectedItemId}/${Math.random()
+ .toString(16)
+ .slice(2)}-${file.name}`;
+ const result = await supabase?.storage
+ .from("private")
+ .upload(fileName, file);
+
+ if (result?.error) {
+ throw new Error(result.error.message);
+ }
+
+ if (!result?.data) {
+ throw new Error("Failed to upload image");
+ }
+
+ return `/file/preview/private/${result.data.path}`;
+ };
+
const [tabChangeRerender, setTabChangeRerender] = useState<number>(1);
const renderListItem = ({
item,
@@ -274,6 +296,7 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
item.data.methodOperationWorkInstruction?.content ??
({} as JSONContent)
}
+ onUpload={onUploadImage}
onChange={onUpdateWorkInstruction}
/>
</motion.div>
@@ -467,9 +490,11 @@ function OperationForm({
const [workCellData, setWorkCellData] = useState<{
workCellTypeId: string;
description: string;
+ standardFactor: string;
}>({
workCellTypeId: item.data.workCellTypeId ?? "",
description: item.data.description ?? "",
+ standardFactor: item.data.standardFactor ?? "Hours/Piece",
});
const onWorkCellChange = async (workCellTypeId: string) => {
@@ -485,6 +510,7 @@ function OperationForm({
setWorkCellData({
workCellTypeId,
description: data?.name ?? "",
+ standardFactor: data?.defaultStandardFactor ?? "Hours/Piece",
});
};
@@ -590,7 +616,17 @@ function OperationForm({
label="Production Standard"
minValue={0}
/>
- <StandardFactor name="standardFactor" label="Standard Factor" />
+ <StandardFactor
+ name="standardFactor"
+ label="Standard Factor"
+ value={workCellData.standardFactor}
+ onChange={(newValue) => {
+ setWorkCellData((d) => ({
+ ...d,
+ standardFactor: newValue?.value ?? "Hours/Piece",
+ }));
+ }}
+ />
</div>
<motion.div
className="flex w-full items-center justify-end p-2"
@@ -602,7 +638,7 @@ function OperationForm({
duration: 0.55,
}}
>
- <motion.div layout className="ml-auto mr-1 pt-2">
+ <motion.div layout className="ml-auto mr-1 pt-2">
<Submit>Save</Submit>
</motion.div>
</motion.div>
diff --git a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
index d738a4eee0..7503ba4b5a 100644
--- a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
@@ -107,6 +107,7 @@ const WorkCellTypeForm = ({
<StandardFactor
name="defaultStandardFactor"
label="Default Standard Factor"
+ value={initialValues.defaultStandardFactor}
/>
<CustomFormFields table="workCellType" />
</VStack>
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
index 0cccfa546f..42f3ff71bb 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationOperationForm.tsx
@@ -205,6 +205,7 @@ const QuotationOperationForm = ({
label="Production Standard"
minValue={0}
/>
+ {/* TODO: this should be controlled when the work center changes */}
<StandardFactor name="standardFactor" label="Standard Factor" />
<NumberControlled
diff --git a/apps/carbon/app/routes/x+/_layout.tsx b/apps/carbon/app/routes/x+/_layout.tsx
index c1f014f84a..92ac1ebf62 100644
--- a/apps/carbon/app/routes/x+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/_layout.tsx
@@ -131,7 +131,7 @@ export default function AuthenticatedRoute() {
</div>
</div>
</div>
- <Toaster richColors position="bottom-right" />
+ <Toaster position="bottom-right" />
</TooltipProvider>
</RealtimeDataProvider>
</SupabaseProvider>
diff --git a/apps/website/src/components/CompanyForm.tsx b/apps/website/src/components/CompanyForm.tsx
index 5d0a0ebd6a..f3184ef5ed 100644
--- a/apps/website/src/components/CompanyForm.tsx
+++ b/apps/website/src/components/CompanyForm.tsx
@@ -154,7 +154,7 @@ export default function CompanyForm() {
</Card>
</form>
</Form>
- <Toaster richColors />
+ <Toaster />
</>
);
}
diff --git a/apps/website/src/components/ContactForm.tsx b/apps/website/src/components/ContactForm.tsx
index 49634da3ca..e40a03d516 100644
--- a/apps/website/src/components/ContactForm.tsx
+++ b/apps/website/src/components/ContactForm.tsx
@@ -69,7 +69,7 @@ export default function ContactForm() {
</Button>
</form>
</Form>
- <Toaster richColors />
+ <Toaster />
</>
);
}
diff --git a/packages/database/supabase/migrations/20240623115054_parts-documents-rls.sql b/packages/database/supabase/migrations/20240623115054_parts-documents-rls.sql
new file mode 100644
index 0000000000..6efc9f7489
--- /dev/null
+++ b/packages/database/supabase/migrations/20240623115054_parts-documents-rls.sql
@@ -0,0 +1,40 @@
+-- Parts documents
+CREATE POLICY "Employees can view internal parts documents" ON storage.objects
+FOR SELECT USING (
+ bucket_id = 'private'
+ AND has_role('employee')
+ AND (storage.foldername(name))[1] = ANY(
+ select "companyId" from "userToCompany" where "userId" = auth.uid()::text
+ )
+ AND (storage.foldername(name))[2] = 'parts'
+);
+
+CREATE POLICY "Internal parts documents insert requires parts_create" ON storage.objects
+FOR INSERT WITH CHECK (
+ bucket_id = 'private'
+ AND has_role('employee')
+ AND (storage.foldername(name))[1] = ANY(
+ get_permission_companies('parts_create')
+ )
+ AND (storage.foldername(name))[2] = 'parts'
+);
+
+CREATE POLICY "Internal parts documents update requires parts_update" ON storage.objects
+FOR UPDATE USING (
+ bucket_id = 'private'
+ AND has_role('employee')
+ AND (storage.foldername(name))[1] = ANY(
+ get_permission_companies('parts_update')
+ )
+ AND (storage.foldername(name))[2] = 'parts'
+);
+
+CREATE POLICY "Internal parts documents delete requires parts_delete" ON storage.objects
+FOR DELETE USING (
+ bucket_id = 'private'
+ AND has_role('employee')
+ AND (storage.foldername(name))[1] = ANY(
+ get_permission_companies('parts_delete')
+ )
+ AND (storage.foldername(name))[2] = 'parts'
+);