Skip to content

Commit

Permalink
Merge pull request #131 from Maker-Management-Platform/124-bug-create…
Browse files Browse the repository at this point in the history
…-printer-without-name

BUG create printer without name #124
  • Loading branch information
EduardoOliveira authored Feb 29, 2024
2 parents d9d69dd + 16d5d0f commit a2e68fa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/printers/components/parts/printer-form/PrinterForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SettingsContext } from "@/core/settings/settingsContext";
import { Printer, printerTypes } from "@/printers/entities/Printer";
import { ActionIcon, Button, Group, Input, Select, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";
import { hasLength, isNotEmpty, useForm } from "@mantine/form";
import { notifications } from "@mantine/notifications";
import { IconPlugConnected } from "@tabler/icons-react";
import useAxios from "axios-hooks";
Expand All @@ -16,10 +16,14 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {
const { settings } = useContext(SettingsContext);
const form = useForm({
initialValues: {
...printer,
name: '',
type: '',
address: '',
},
validate: {
name: (value) => (value.length < 2 ? 'Too short name' : null),
name: hasLength({ min: 3 }, "Use at least 3 characters"),
type: isNotEmpty("You must select a printer type."),
address: hasLength({ min: 8 }, "You must insert an address (with http://)")
},
});
const [{ loading }, executeSave] = useAxios({ method: 'POST' }, { manual: true })
Expand Down Expand Up @@ -66,7 +70,7 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {

}

return (<>
return (
<form onSubmit={form.onSubmit(onSave)}>
<TextInput
mb="sm"
Expand Down Expand Up @@ -110,8 +114,8 @@ export function PrinterForm({ printer, onPrinterChange }: PrinterFormProps) {
{...form.getInputProps('state')}
/>}
<Group justify="flex-end" mt="md">
<Button type="submit" loading={loading} onClick={onSave}>Save</Button>
<Button type="submit" loading={loading}>Save</Button>
</Group>
</form>
</>)
)
}

0 comments on commit a2e68fa

Please sign in to comment.