@@ -1,11 +1,18 @@
|
||||
import { Head, useForm } from '@inertiajs/react';
|
||||
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import { Head, router, useForm } from '@inertiajs/react';
|
||||
import { FormErrors, PageTitle, Panel } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
export default function Setup() {
|
||||
const form = useForm({
|
||||
const identity = useProcurementPreparationIdentity('company-setup');
|
||||
return <SetupFields key={identity} identity={identity} />;
|
||||
}
|
||||
function SetupFields({ identity }: { identity: string }) {
|
||||
const initial = {
|
||||
name: '',
|
||||
department: '',
|
||||
second_name: '',
|
||||
@@ -15,7 +22,13 @@ export default function Setup() {
|
||||
first_limit: '',
|
||||
second_limit: '',
|
||||
includes_tax: true,
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial).dontRemember(
|
||||
'second_password',
|
||||
'second_password_confirmation',
|
||||
);
|
||||
const dirty = hasPreparationChanges(initial, { ...initial, ...form.data });
|
||||
const ref = usePreparationDirty(dirty);
|
||||
return (
|
||||
<>
|
||||
<Head title="Configurar empresa" />
|
||||
@@ -27,9 +40,27 @@ export default function Setup() {
|
||||
/>
|
||||
<Panel title="Dados da organização">
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/empresa/iniciar');
|
||||
form.post('/empresa/iniciar', {
|
||||
onSuccess: () => {
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
const {
|
||||
second_password: _password,
|
||||
second_password_confirmation:
|
||||
_confirmation,
|
||||
...remembered
|
||||
} = initial;
|
||||
router.remember(
|
||||
remembered,
|
||||
`${identity}:data`,
|
||||
);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
className="space-y-5"
|
||||
>
|
||||
@@ -101,7 +132,7 @@ export default function Setup() {
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
minLength={12}
|
||||
value={form.data.second_password}
|
||||
value={form.data.second_password ?? ''}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'second_password',
|
||||
@@ -117,7 +148,8 @@ export default function Setup() {
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={
|
||||
form.data.second_password_confirmation
|
||||
form.data
|
||||
.second_password_confirmation ?? ''
|
||||
}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
@@ -180,6 +212,10 @@ export default function Setup() {
|
||||
Aplicar os limites ao valor com imposto
|
||||
</label>
|
||||
</fieldset>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
As palavras-passe não são conservadas ao sair deste
|
||||
ecrã.
|
||||
</p>
|
||||
<Button disabled={form.processing}>
|
||||
Criar empresa
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user