@@ -1,3 +1,9 @@
|
||||
import { AdministrativeLocation } from '@/components/administrative-location';
|
||||
import type {
|
||||
GeographyDescription,
|
||||
GeographyReference,
|
||||
} from '@/components/administrative-location';
|
||||
import { TerritorialFilter } from '@/components/territorial-filter';
|
||||
import { Head, useForm, Link } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { InventoryNotice, InventoryPagination } from '@/components/inventory';
|
||||
@@ -20,6 +26,7 @@ type Level = {
|
||||
is_critical: boolean;
|
||||
};
|
||||
type Asset = {
|
||||
geography_reference?: GeographyReference | null;
|
||||
id: number;
|
||||
code: string;
|
||||
description: string;
|
||||
@@ -57,6 +64,9 @@ type History = {
|
||||
};
|
||||
};
|
||||
type Props = {
|
||||
geographyEnabled?: boolean;
|
||||
equipmentGeography?: Record<number, GeographyDescription>;
|
||||
geographyFilter?: GeographyDescription;
|
||||
equipment: Asset[];
|
||||
parts: Part[];
|
||||
levels: Level[];
|
||||
@@ -98,6 +108,9 @@ export default function EquipmentPage({
|
||||
canManage,
|
||||
canConfigure,
|
||||
demo = false,
|
||||
geographyEnabled = false,
|
||||
equipmentGeography = {},
|
||||
geographyFilter = null,
|
||||
}: Props) {
|
||||
const [message, setMessage] = useState('');
|
||||
const category = useForm({
|
||||
@@ -107,6 +120,7 @@ export default function EquipmentPage({
|
||||
is_critical: '',
|
||||
});
|
||||
const asset = useForm({
|
||||
geography_reference: null as GeographyReference | null,
|
||||
id: '',
|
||||
version: '',
|
||||
code: '',
|
||||
@@ -143,6 +157,14 @@ export default function EquipmentPage({
|
||||
description="Cadastro, peças compatíveis, mínimos explícitos e rastreabilidade das saídas."
|
||||
/>
|
||||
<InventoryNotice />
|
||||
{geographyEnabled && !demo && (
|
||||
<Panel title="Localização dos equipamentos">
|
||||
<TerritorialFilter
|
||||
target="/equipamentos"
|
||||
initial={geographyFilter}
|
||||
/>
|
||||
</Panel>
|
||||
)}
|
||||
{demo && (
|
||||
<p className="rounded-lg border bg-teal-50 p-4 text-sm text-teal-900">
|
||||
Dados fictícios para revisão sem login. Formulários
|
||||
@@ -179,6 +201,12 @@ export default function EquipmentPage({
|
||||
<strong>
|
||||
{e.code} · {e.description}
|
||||
</strong>
|
||||
<Link
|
||||
className="mt-2 block underline"
|
||||
href={`/equipamentos/${e.id}`}
|
||||
>
|
||||
Acompanhar compras e movimentos
|
||||
</Link>
|
||||
<p className="mt-2">
|
||||
{e.area} ·{' '}
|
||||
{
|
||||
@@ -193,6 +221,14 @@ export default function EquipmentPage({
|
||||
Criticidade:{' '}
|
||||
{criticality(e.criticality_level_id)?.name}
|
||||
</p>
|
||||
{equipmentGeography[e.id]?.path.length ? (
|
||||
<p className="text-muted-foreground">
|
||||
Localização actual:{' '}
|
||||
{equipmentGeography[e.id]?.path
|
||||
.map((node) => node.name)
|
||||
.join(' / ')}
|
||||
</p>
|
||||
) : null}
|
||||
{e.stock_item_id && (
|
||||
<p>
|
||||
Artigo: {stock(e.stock_item_id)?.code}
|
||||
@@ -220,6 +256,9 @@ export default function EquipmentPage({
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
asset.setData({
|
||||
geography_reference:
|
||||
e.geography_reference ??
|
||||
null,
|
||||
id: String(e.id),
|
||||
version: String(e.version),
|
||||
code: e.code,
|
||||
@@ -332,12 +371,36 @@ export default function EquipmentPage({
|
||||
simulate();
|
||||
return;
|
||||
}
|
||||
asset.transform((data) => {
|
||||
const { geography_reference, ...rest } =
|
||||
data;
|
||||
return geographyEnabled
|
||||
? { ...rest, geography_reference }
|
||||
: rest;
|
||||
});
|
||||
asset.post('/equipamentos/activos', {
|
||||
onSuccess: () => asset.reset(),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={asset.errors} />
|
||||
{geographyEnabled && !demo && (
|
||||
<AdministrativeLocation
|
||||
key={asset.data.id || 'new'}
|
||||
value={asset.data.geography_reference}
|
||||
initial={
|
||||
equipmentGeography[
|
||||
Number(asset.data.id)
|
||||
] ?? null
|
||||
}
|
||||
onChange={(value) =>
|
||||
asset.setData(
|
||||
'geography_reference',
|
||||
value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{(
|
||||
[
|
||||
'code',
|
||||
|
||||
Reference in New Issue
Block a user