Registry: fix trailers table alignment in truck view, add created on/by, default new driver nationality to Jordan
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3a230fd556
commit
91d6416198
|
|
@ -41,6 +41,8 @@ export function truckGrid(h: { isCompanyUser: boolean; onOpen: (r: TruckRow) =>
|
||||||
export const connectedTrailerColumns = (): GridMeta<TrailerRow>['columns'] => [
|
export const connectedTrailerColumns = (): GridMeta<TrailerRow>['columns'] => [
|
||||||
{ key: 'tn', header: lbl('Trailer', 'المقطورة'), ltr: true },
|
{ key: 'tn', header: lbl('Trailer', 'المقطورة'), ltr: true },
|
||||||
{ key: 'regDate', header: lbl('License expiry', 'انتهاء الترخيص'), format: 'date', ltr: true, hideBelow: 'md' },
|
{ key: 'regDate', header: lbl('License expiry', 'انتهاء الترخيص'), format: 'date', ltr: true, hideBelow: 'md' },
|
||||||
|
{ key: 'createTimestamp', header: lbl('Created on', 'تاريخ الإنشاء'), format: 'datetime', ltr: true },
|
||||||
|
{ key: 'createUserId', header: lbl('Created by', 'أنشئ بواسطة'), ltr: true },
|
||||||
{ key: 'statusCode', header: lbl('Status', 'الحالة'), format: 'status', statuses: registryStatuses },
|
{ key: 'statusCode', header: lbl('Status', 'الحالة'), format: 'status', statuses: registryStatuses },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import {
|
import {
|
||||||
Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Stack, Table, TableBody, TableCell, TableContainer,
|
Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, Paper, Stack, Table, TableBody, TableCell, TableContainer,
|
||||||
TableHead, TableRow, TextField, Typography,
|
TableHead, TableRow, TextField, Typography,
|
||||||
|
|
@ -14,7 +15,7 @@ import { LoadingBanner } from '@/components/LoadingBanner';
|
||||||
import { MetaForm } from '@/components/MetaForm';
|
import { MetaForm } from '@/components/MetaForm';
|
||||||
import { PageHeader } from '@/components/PageHeader';
|
import { PageHeader } from '@/components/PageHeader';
|
||||||
import { StatusChip } from '@/components/StatusChip';
|
import { StatusChip } from '@/components/StatusChip';
|
||||||
import { formatDate, formatNumber } from '@/components/meta/format';
|
import { formatDate, formatDateTime, formatNumber } from '@/components/meta/format';
|
||||||
import { useFeatureUi } from '@/i18n/useUi';
|
import { useFeatureUi } from '@/i18n/useUi';
|
||||||
import { useConfirm } from '@/providers/ConfirmProvider';
|
import { useConfirm } from '@/providers/ConfirmProvider';
|
||||||
import { useAuth } from '@/providers/AuthProvider';
|
import { useAuth } from '@/providers/AuthProvider';
|
||||||
|
|
@ -23,7 +24,7 @@ import { downloadFile } from '../grains-orders/api';
|
||||||
import {
|
import {
|
||||||
useAddBlacklist, useCancelBlacklist, useCreateDriver, useCreateTrailer, useCreateTruck, useDestinationOptions, useDriver,
|
useAddBlacklist, useCancelBlacklist, useCreateDriver, useCreateTrailer, useCreateTruck, useDestinationOptions, useDriver,
|
||||||
useDriverAction, useLocationTruckCounts, usePermissions, useSaveWeighbridge, useTrailer, useTrailerAction, useTruck,
|
useDriverAction, useLocationTruckCounts, usePermissions, useSaveWeighbridge, useTrailer, useTrailerAction, useTruck,
|
||||||
useTruckAction, useTruckTrailers, useUpdateTrailer, useUpdateTruck,
|
useTruckAction, useTruckTrailers, useUpdateTrailer, useUpdateTruck, nationalityOptions,
|
||||||
} from './api';
|
} from './api';
|
||||||
import { Card, DestinationsPanel, DocumentsSection, num, withDocumentIds, type PendingDoc } from './components';
|
import { Card, DestinationsPanel, DocumentsSection, num, withDocumentIds, type PendingDoc } from './components';
|
||||||
import { blacklistForm, blacklistGrid, weighbridgeForm } from './meta/blacklist';
|
import { blacklistForm, blacklistGrid, weighbridgeForm } from './meta/blacklist';
|
||||||
|
|
@ -275,10 +276,11 @@ function ConnectedTrailers({ rows, loading, truckId }: { rows: TrailerRow[]; loa
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{rows.map((r) => (
|
{rows.map((r) => (
|
||||||
<TableRow key={r.id} hover sx={{ cursor: 'pointer' }} onClick={() => navigate(`${ROOT}/trailers/${r.id}?truckId=${truckId}`)}>
|
<TableRow key={r.id} hover sx={{ cursor: 'pointer' }} onClick={() => navigate(`${ROOT}/trailers/${r.id}?truckId=${truckId}`)}>
|
||||||
<TableCell dir="ltr" sx={{ textAlign: 'start' }}>{r.tn}</TableCell>
|
<TableCell sx={{ textAlign: 'start' }}><bdi dir="ltr">{r.tn}</bdi></TableCell>
|
||||||
<TableCell dir="ltr" sx={{ textAlign: 'start' }}>{r.chasesNumber}</TableCell>
|
<TableCell sx={{ textAlign: 'start' }}><bdi dir="ltr">{formatDate(r.regDate, lang)}</bdi></TableCell>
|
||||||
<TableCell dir="ltr" sx={{ textAlign: 'start' }}>{formatDate(r.regDate, lang)}</TableCell>
|
<TableCell sx={{ textAlign: 'start' }}><bdi dir="ltr">{formatDateTime(r.createTimestamp, lang)}</bdi></TableCell>
|
||||||
<TableCell><StatusChip value={r.statusCode} statuses={registryStatuses} /></TableCell>
|
<TableCell sx={{ textAlign: 'start' }}><bdi dir="ltr">{r.createUserId}</bdi></TableCell>
|
||||||
|
<TableCell sx={{ textAlign: 'start' }}><StatusChip value={r.statusCode} statuses={registryStatuses} /></TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|
@ -468,9 +470,19 @@ export function DriverPage() {
|
||||||
const pending = usePendingDocs();
|
const pending = usePendingDocs();
|
||||||
const d = driver.data;
|
const d = driver.data;
|
||||||
const meta = useMemo(() => driverForm({ isCreate: isNew }), [isNew]);
|
const meta = useMemo(() => driverForm({ isCreate: isNew }), [isNew]);
|
||||||
|
// new driver: nationality defaults to Jordan (found by name: the lookup code is a database value)
|
||||||
|
const nationalities = useQuery({
|
||||||
|
queryKey: ['grains.registry.nationalities.default'],
|
||||||
|
queryFn: () => nationalityOptions.load({ lang: 'ar' }),
|
||||||
|
enabled: isNew,
|
||||||
|
staleTime: 5 * 60_000,
|
||||||
|
});
|
||||||
|
const jordan = nationalities.data?.find((o) => /أردن|jordan/i.test(String(o.label)))?.value;
|
||||||
const initial = useMemo(
|
const initial = useMemo(
|
||||||
() => (d ? { nnpn: d.nnpn, name: d.name, nat: d.nat, dln: d.dln, dled: isoDay(d.dled), cat: d.cat, mobile1: d.mobile1, mobile2: d.mobile2 } : {}),
|
() => (d
|
||||||
[d],
|
? { nnpn: d.nnpn, name: d.name, nat: d.nat, dln: d.dln, dled: isoDay(d.dled), cat: d.cat, mobile1: d.mobile1, mobile2: d.mobile2 }
|
||||||
|
: jordan !== undefined ? { nat: jordan } : {}),
|
||||||
|
[d, jordan],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loading || (!isNew && driver.isLoading)) return <LoadingBanner />;
|
if (loading || (!isNew && driver.isLoading)) return <LoadingBanner />;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue