@@ -1,3 +1,8 @@
|
||||
import { AdministrativeLocation } from '@/components/administrative-location';
|
||||
import type {
|
||||
GeographyReference,
|
||||
GeographyDescription,
|
||||
} from '@/components/administrative-location';
|
||||
import { Head, Link, router, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
@@ -50,6 +55,8 @@ export default function Suppliers({
|
||||
suppliers,
|
||||
filters,
|
||||
canCreate,
|
||||
geographyEnabled = false,
|
||||
geographyFilter = null,
|
||||
canReview,
|
||||
}: {
|
||||
suppliers: {
|
||||
@@ -57,11 +64,14 @@ export default function Suppliers({
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
filters: { search?: string };
|
||||
filters: { search?: string; location?: string };
|
||||
canCreate: boolean;
|
||||
geographyEnabled?: boolean;
|
||||
geographyFilter?: GeographyDescription;
|
||||
canReview: boolean;
|
||||
}) {
|
||||
const form = useForm({
|
||||
geography_reference: null as GeographyReference | null,
|
||||
name: '',
|
||||
nuit: '',
|
||||
contact: '',
|
||||
@@ -78,6 +88,9 @@ export default function Suppliers({
|
||||
const review = useForm({ status: 'active', comment: '', version: 0 });
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [selected, setSelected] = useState<Supplier | null>(null);
|
||||
const [location, setLocation] = useState<GeographyReference | null>(
|
||||
geographyFilter?.reference ?? null,
|
||||
);
|
||||
const [search, setSearch] = useState(filters.search ?? '');
|
||||
return (
|
||||
<>
|
||||
@@ -103,6 +116,13 @@ export default function Suppliers({
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.transform((data) => {
|
||||
const { geography_reference, ...rest } =
|
||||
data;
|
||||
return geographyEnabled
|
||||
? { ...rest, geography_reference }
|
||||
: rest;
|
||||
});
|
||||
form.post('/fornecedores', {
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
@@ -112,6 +132,17 @@ export default function Suppliers({
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
{geographyEnabled && (
|
||||
<AdministrativeLocation
|
||||
value={form.data.geography_reference}
|
||||
onChange={(value) =>
|
||||
form.setData(
|
||||
'geography_reference',
|
||||
value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{Object.entries(fields).map(([key, label]) => {
|
||||
const name = key as keyof typeof fields;
|
||||
@@ -167,13 +198,22 @@ export default function Suppliers({
|
||||
</Panel>
|
||||
)}
|
||||
<Panel title="Directório de fornecedores">
|
||||
{geographyEnabled && (
|
||||
<div className="mb-5">
|
||||
<AdministrativeLocation
|
||||
value={location}
|
||||
initial={geographyFilter}
|
||||
onChange={setLocation}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<form
|
||||
className="mb-5 flex gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
router.get(
|
||||
'/fornecedores',
|
||||
{ search },
|
||||
{ search, location: location?.record_id ?? '' },
|
||||
{ preserveState: true },
|
||||
);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user