Formatted some client files
This commit is contained in:
@@ -14,7 +14,7 @@ interface CreateOrCloneProps {
|
||||
export const FilamentCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps> = (props) => {
|
||||
const t = useTranslate();
|
||||
|
||||
const { form, formProps, saveButtonProps, formLoading, onFinish, redirect } = useForm<IFilament>();
|
||||
const { form, formProps, formLoading, onFinish, redirect } = useForm<IFilament>();
|
||||
|
||||
if (props.mode === "clone" && formProps.initialValues) {
|
||||
// Fix the vendor_id
|
||||
@@ -24,10 +24,10 @@ export const FilamentCreate: React.FC<IResourceComponentsProps & CreateOrClonePr
|
||||
}
|
||||
|
||||
const handleSubmit = async (redirectTo: "list" | "edit" | "create") => {
|
||||
let values = await form.validateFields();
|
||||
const values = await form.validateFields();
|
||||
await onFinish(values);
|
||||
redirect(redirectTo, (values as IFilament).id);
|
||||
}
|
||||
};
|
||||
|
||||
const { selectProps } = useSelect<IVendor>({
|
||||
resource: "vendor",
|
||||
@@ -40,8 +40,12 @@ export const FilamentCreate: React.FC<IResourceComponentsProps & CreateOrClonePr
|
||||
isLoading={formLoading}
|
||||
footerButtons={() => (
|
||||
<>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>{t("buttons.save")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>{t("buttons.saveAndAdd")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>
|
||||
{t("buttons.save")}
|
||||
</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>
|
||||
{t("buttons.saveAndAdd")}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -7,7 +7,6 @@ import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import { IFilament } from "./model";
|
||||
import { enrichText } from "../../utils/parsing";
|
||||
import { IVendor } from "../vendors/model";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
dayjs.extend(utc);
|
||||
|
||||
@@ -34,19 +33,22 @@ export const FilamentShow: React.FC<IResourceComponentsProps> = () => {
|
||||
const gotoVendor = (): undefined => {
|
||||
const URL = `/vendor/show/${record?.vendor?.id}`;
|
||||
navigate(URL);
|
||||
}
|
||||
};
|
||||
|
||||
const gotoSpools = (): undefined => {
|
||||
const URL = `/spool#filters=[{"field":"filament.id","operator":"in","value":[${record?.id}]}]`
|
||||
const URL = `/spool#filters=[{"field":"filament.id","operator":"in","value":[${record?.id}]}]`;
|
||||
navigate(URL);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Show isLoading={isLoading} title={record ? formatTitle(record) : ""}>
|
||||
<Title level={5}>{t("filament.fields.id")}</Title>
|
||||
<NumberField value={record?.id ?? ""} />
|
||||
<Title level={5}>{t("filament.fields.vendor")}</Title>
|
||||
<button onClick={gotoVendor} style={{ background: 'none', border: 'none', color: 'blue', cursor: 'pointer', paddingLeft: 0 }}>
|
||||
<button
|
||||
onClick={gotoVendor}
|
||||
style={{ background: "none", border: "none", color: "blue", cursor: "pointer", paddingLeft: 0 }}
|
||||
>
|
||||
{record ? record.vendor?.name : ""}
|
||||
</button>
|
||||
<Title level={5}>{t("filament.fields.registered")}</Title>
|
||||
@@ -118,10 +120,13 @@ export const FilamentShow: React.FC<IResourceComponentsProps> = () => {
|
||||
<Title level={5}>{t("filament.fields.comment")}</Title>
|
||||
<TextField value={enrichText(record?.comment)} />
|
||||
<Title level={5}>{t("filament.fields.spools")}</Title>
|
||||
<button onClick={gotoSpools} style={{ background: 'none', border: 'none', color: 'blue', cursor: 'pointer', paddingLeft: 0 }}>
|
||||
<button
|
||||
onClick={gotoSpools}
|
||||
style={{ background: "none", border: "none", color: "blue", cursor: "pointer", paddingLeft: 0 }}
|
||||
>
|
||||
{record ? formatTitle(record) : ""}
|
||||
</button>
|
||||
</Show >
|
||||
</Show>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
import { IResourceComponentsProps, useTranslate } from "@refinedev/core";
|
||||
import { Create, useForm, useSelect } from "@refinedev/antd";
|
||||
import { Form, Input, DatePicker, Select, InputNumber, Radio, Divider, Button } from "antd";
|
||||
@@ -9,7 +9,7 @@ import { ISpool } from "./model";
|
||||
import { numberFormatter, numberParser } from "../../utils/parsing";
|
||||
import { useSpoolmanLocations } from "../../components/otherModels";
|
||||
import { MinusOutlined, PlusOutlined } from "@ant-design/icons";
|
||||
import '../../utils/overrides.css'
|
||||
import "../../utils/overrides.css";
|
||||
|
||||
interface CreateOrCloneProps {
|
||||
mode: "create" | "clone";
|
||||
@@ -20,7 +20,7 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
||||
|
||||
const { form, formProps, formLoading, onFinish, redirect } = useForm<ISpool>({
|
||||
redirect: false,
|
||||
warnWhenUnsavedChanges: false
|
||||
warnWhenUnsavedChanges: false,
|
||||
});
|
||||
|
||||
if (props.mode === "clone" && formProps.initialValues) {
|
||||
@@ -34,16 +34,16 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
||||
}
|
||||
|
||||
const handleSubmit = async (redirectTo: "list" | "edit" | "create") => {
|
||||
let values = await form.validateFields();
|
||||
const values = await form.validateFields();
|
||||
if (quantity > 1) {
|
||||
let submit = Array(quantity).fill(values);
|
||||
const submit = Array(quantity).fill(values);
|
||||
// queue multiple creates this way for now Refine doesn't seem to map Arrays to createMany or multiple creates like it says it does
|
||||
submit.forEach(async r => await onFinish(r));
|
||||
submit.forEach(async (r) => await onFinish(r));
|
||||
} else {
|
||||
await onFinish(values);
|
||||
}
|
||||
redirect(redirectTo, (values as ISpool).id);
|
||||
}
|
||||
};
|
||||
|
||||
const { queryResult } = useSelect<IFilament>({
|
||||
resource: "filament",
|
||||
@@ -120,11 +120,11 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
||||
const [quantity, setQuantity] = useState(1);
|
||||
const incrementQty = () => {
|
||||
setQuantity(quantity + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const decrementQty = () => {
|
||||
setQuantity(quantity - 1);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Create
|
||||
@@ -132,27 +132,25 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
||||
isLoading={formLoading}
|
||||
footerButtons={() => (
|
||||
<>
|
||||
<div style={{ display: 'flex', backgroundColor: '#141414', border: '1px solid #424242', borderRadius: '6px' }}>
|
||||
<div
|
||||
style={{ display: "flex", backgroundColor: "#141414", border: "1px solid #424242", borderRadius: "6px" }}
|
||||
>
|
||||
<Button type="text" style={{ padding: 0, width: 32, height: 32 }} onClick={decrementQty}>
|
||||
<MinusOutlined />
|
||||
</Button>
|
||||
<InputNumber
|
||||
name="Quantity"
|
||||
min={1}
|
||||
id="qty-input"
|
||||
controls={false}
|
||||
value={quantity}
|
||||
>
|
||||
</InputNumber>
|
||||
<InputNumber name="Quantity" min={1} id="qty-input" controls={false} value={quantity}></InputNumber>
|
||||
<Button type="text" style={{ padding: 0, width: 32, height: 32 }} onClick={incrementQty}>
|
||||
<PlusOutlined />
|
||||
</Button>
|
||||
</div>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>{t("buttons.save")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>{t("buttons.saveAndAdd")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>
|
||||
{t("buttons.save")}
|
||||
</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>
|
||||
{t("buttons.saveAndAdd")}
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
)}
|
||||
>
|
||||
<Form {...formProps} layout="vertical">
|
||||
<Form.Item
|
||||
@@ -326,7 +324,7 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
|
||||
<TextArea maxLength={1024} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Create >
|
||||
</Create>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
14
client/src/pages/vendors/create.tsx
vendored
14
client/src/pages/vendors/create.tsx
vendored
@@ -12,13 +12,13 @@ interface CreateOrCloneProps {
|
||||
export const VendorCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps> = (props) => {
|
||||
const t = useTranslate();
|
||||
|
||||
const { form, formProps, saveButtonProps, formLoading, onFinish, redirect } = useForm<IVendor>();
|
||||
const { form, formProps, formLoading, onFinish, redirect } = useForm<IVendor>();
|
||||
|
||||
const handleSubmit = async (redirectTo: "list" | "edit" | "create") => {
|
||||
let values = await form.validateFields();
|
||||
const values = await form.validateFields();
|
||||
await onFinish(values);
|
||||
redirect(redirectTo, (values as IVendor).id);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Create
|
||||
@@ -26,8 +26,12 @@ export const VendorCreate: React.FC<IResourceComponentsProps & CreateOrCloneProp
|
||||
isLoading={formLoading}
|
||||
footerButtons={() => (
|
||||
<>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>{t("buttons.save")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>{t("buttons.saveAndAdd")}</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("list")}>
|
||||
{t("buttons.save")}
|
||||
</Button>
|
||||
<Button type="primary" onClick={() => handleSubmit("create")}>
|
||||
{t("buttons.saveAndAdd")}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user