commit de armazens
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-04 09:40:26 +02:00
parent e753f7a0a4
commit 63d20b10fc
245 changed files with 10847 additions and 230 deletions
+31 -1
View File
@@ -1,3 +1,8 @@
import { AdministrativeLocation } from '@/components/administrative-location';
import type {
GeographyDescription,
GeographyReference,
} from '@/components/administrative-location';
import { Head, Link, useForm } from '@inertiajs/react';
import {
FormErrors,
@@ -11,8 +16,18 @@ import { Label } from '@/components/ui/label';
import { supplierFields } from '@/types/supplier';
import type { Supplier } from '@/types/supplier';
export default function EditSupplier({ supplier }: { supplier: Supplier }) {
export default function EditSupplier({
supplier,
geographyEnabled = false,
geography = null,
}: {
supplier: Supplier;
geographyEnabled?: boolean;
geography?: GeographyDescription;
}) {
const form = useForm({
geography_reference:
supplier.geography_reference ?? (null as GeographyReference | null),
name: supplier.name,
nuit: supplier.nuit,
contact: supplier.contact,
@@ -46,10 +61,25 @@ export default function EditSupplier({ supplier }: { supplier: Supplier }) {
className="space-y-5"
onSubmit={(e) => {
e.preventDefault();
form.transform((data) => {
const { geography_reference, ...rest } = data;
return geographyEnabled
? { ...rest, geography_reference }
: rest;
});
form.put(`/fornecedores/${supplier.id}`);
}}
>
<FormErrors errors={form.errors} />
{geographyEnabled && (
<AdministrativeLocation
value={form.data.geography_reference}
initial={geography}
onChange={(value) =>
form.setData('geography_reference', value)
}
/>
)}
<div className="grid gap-4 md:grid-cols-2">
{Object.entries(supplierFields).map(
([key, label]) => {
+42 -2
View File
@@ -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 },
);
}}
+14
View File
@@ -1,3 +1,4 @@
import type { GeographyDescription } from '@/components/administrative-location';
import { Head, Link, useForm } from '@inertiajs/react';
import { Download, FileLock2, Pencil, Upload } from 'lucide-react';
import { useRef } from 'react';
@@ -27,6 +28,7 @@ type Document = {
sha256: string;
};
type Props = {
geography?: GeographyDescription;
supplier: Supplier;
documents: Document[];
canEdit: boolean;
@@ -36,6 +38,7 @@ type Props = {
export default function SupplierShow({
supplier,
geography = null,
documents,
canEdit,
canDocuments,
@@ -69,6 +72,17 @@ export default function SupplierShow({
}
/>
<Panel title="Dados do fornecedor">
{geography && (
<p className="mb-4 text-sm">
Localização administrativa:{' '}
{geography.path
.map((node) => node.name)
.join(' / ')}
{geography.requires_review
? ' (requer revisão)'
: ''}
</p>
)}
{canDocuments && (
<Link
className="mb-4 inline-block font-semibold text-teal-700"