Skip to content
This repository was archived by the owner on Jan 31, 2026. It is now read-only.

Commit a2e68fa

Browse files
Merge pull request #131 from Maker-Management-Platform/124-bug-create-printer-without-name
BUG create printer without name #124
2 parents d9d69dd + 16d5d0f commit a2e68fa

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/printers/components/parts/printer-form/PrinterForm.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SettingsContext } from "@/core/settings/settingsContext";
22
import { Printer, printerTypes } from "@/printers/entities/Printer";
33
import { ActionIcon, Button, Group, Input, Select, TextInput } from "@mantine/core";
4-
import { useForm } from "@mantine/form";
4+
import { hasLength, isNotEmpty, useForm } from "@mantine/form";
55
import { notifications } from "@mantine/notifications";
66
import { IconPlugConnected } from "@tabler/icons-react";
77
import useAxios from "axios-hooks";
@@ -16,10 +16,14 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {
1616
const { settings } = useContext(SettingsContext);
1717
const form = useForm({
1818
initialValues: {
19-
...printer,
19+
name: '',
20+
type: '',
21+
address: '',
2022
},
2123
validate: {
22-
name: (value) => (value.length < 2 ? 'Too short name' : null),
24+
name: hasLength({ min: 3 }, "Use at least 3 characters"),
25+
type: isNotEmpty("You must select a printer type."),
26+
address: hasLength({ min: 8 }, "You must insert an address (with http://)")
2327
},
2428
});
2529
const [{ loading }, executeSave] = useAxios({ method: 'POST' }, { manual: true })
@@ -66,7 +70,7 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {
6670

6771
}
6872

69-
return (<>
73+
return (
7074
<form onSubmit={form.onSubmit(onSave)}>
7175
<TextInput
7276
mb="sm"
@@ -110,8 +114,8 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {
110114
{...form.getInputProps('state')}
111115
/>}
112116
<Group justify="flex-end" mt="md">
113-
<Button type="submit" loading={loading} onClick={onSave}>Save</Button>
117+
<Button type="submit" loading={loading}>Save</Button>
114118
</Group>
115119
</form>
116-
</>)
120+
)
117121
}

0 commit comments

Comments
 (0)