tiles modified
This commit is contained in:
parent
3bf6757bdf
commit
d30fd56d4f
@ -45,6 +45,8 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [chainedPrefillData, setChainedPrefillData] = useState<Record<string, unknown> | undefined>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -133,6 +135,12 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chainedPrefillData) {
|
||||||
|
Object.entries(chainedPrefillData).forEach(([k, v]) => {
|
||||||
|
if (!imageFieldIds.has(k)) defaultValues[k] = v;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setValues(defaultValues);
|
setValues(defaultValues);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@ -268,6 +276,39 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
|
|||||||
const nextActivity = pending.shift();
|
const nextActivity = pending.shift();
|
||||||
|
|
||||||
if (nextActivity) {
|
if (nextActivity) {
|
||||||
|
let nextPrefillData = undefined;
|
||||||
|
if (nextActivity.activity_uid === ORDER_BOOKING.activities.POTENTIAL_MINING.uid) {
|
||||||
|
try {
|
||||||
|
const pmRes = await client.request<{ potential: { potential: any[] } }>(
|
||||||
|
'POST',
|
||||||
|
'/api/papi2/potential-mining',
|
||||||
|
{ instance_id: String(res.instance_id ?? currentInstanceId) },
|
||||||
|
{ 'TemplateID': '146' }
|
||||||
|
);
|
||||||
|
const rawPotential = pmRes.potential?.potential || [];
|
||||||
|
const mappedPotential = rawPotential.map((row: any) => {
|
||||||
|
const cat = row.product_category || row.product_category_ || row.category;
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
product_category_: cat,
|
||||||
|
product_category: cat,
|
||||||
|
productcategory: cat,
|
||||||
|
category: cat,
|
||||||
|
product_category_1: cat
|
||||||
|
};
|
||||||
|
});
|
||||||
|
nextPrefillData = { potential: mappedPotential };
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to fetch potential mining for chain", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextPrefillData) {
|
||||||
|
setChainedPrefillData(nextPrefillData);
|
||||||
|
} else {
|
||||||
|
setChainedPrefillData(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
setChainQueue(pending);
|
setChainQueue(pending);
|
||||||
setCurrentActivityId(nextActivity.activity_uid);
|
setCurrentActivityId(nextActivity.activity_uid);
|
||||||
setCurrentInstanceId(res.instance_id ?? currentInstanceId);
|
setCurrentInstanceId(res.instance_id ?? currentInstanceId);
|
||||||
|
|||||||
@ -4,8 +4,7 @@ import { ORDER_BOOKING } from '../api/config';
|
|||||||
import { Spinner } from '../components/reusable/Spinner';
|
import { Spinner } from '../components/reusable/Spinner';
|
||||||
import { EmptyState } from '../components/reusable/EmptyState';
|
import { EmptyState } from '../components/reusable/EmptyState';
|
||||||
import { StatsTiles } from '../components/reusable/StatsTiles';
|
import { StatsTiles } from '../components/reusable/StatsTiles';
|
||||||
import { Activity, Package, ShoppingBag, BarChart3, TrendingUp, Phone } from 'lucide-react';
|
import { TrendingUp } from 'lucide-react';
|
||||||
import { formatValue } from '../lib/format';
|
|
||||||
import {
|
import {
|
||||||
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer,
|
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer,
|
||||||
PieChart, Pie, Cell, Legend
|
PieChart, Pie, Cell, Legend
|
||||||
|
|||||||
@ -4,7 +4,8 @@ import { OrdersView } from '../components/rv';
|
|||||||
import { OrderDetail } from '../components/dv';
|
import { OrderDetail } from '../components/dv';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { ShoppingBag } from 'lucide-react';
|
import { ShoppingBag, Plus } from 'lucide-react';
|
||||||
|
import { Button } from '../components/buttons/Button';
|
||||||
import { DynamicForm } from '../components/forms/DynamicForm';
|
import { DynamicForm } from '../components/forms/DynamicForm';
|
||||||
import { ORDER_BOOKING } from '../api/config';
|
import { ORDER_BOOKING } from '../api/config';
|
||||||
import { orderBookingClient } from '../api/clients';
|
import { orderBookingClient } from '../api/clients';
|
||||||
@ -18,11 +19,62 @@ export function OrdersPage() {
|
|||||||
const [refreshKey, setRefreshKey] = useState(0);
|
const [refreshKey, setRefreshKey] = useState(0);
|
||||||
const [activeActivity, setActiveActivity] = useState<{ id: string; name: string } | null>(null);
|
const [activeActivity, setActiveActivity] = useState<{ id: string; name: string } | null>(null);
|
||||||
|
|
||||||
|
const [isFabOpen, setIsFabOpen] = useState(false);
|
||||||
|
const [miningLoading, setMiningLoading] = useState(false);
|
||||||
|
const [miningPrefill, setMiningPrefill] = useState<Record<string, unknown> | undefined>();
|
||||||
|
const [selectedRow, setSelectedRow] = useState<Record<string, any> | null>(null);
|
||||||
|
|
||||||
|
const handlePotentialMiningClick = async () => {
|
||||||
|
setMiningLoading(true);
|
||||||
|
setMiningPrefill(undefined);
|
||||||
|
try {
|
||||||
|
const storeCode = selectedRow?.store_code || selectedRow?.code || selectedRow?.store?.store_code;
|
||||||
|
|
||||||
|
if (!storeCode) {
|
||||||
|
console.warn("Store code not found on selected row, proceeding anyway.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
store_code: storeCode,
|
||||||
|
instance_id: String(instanceId)
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await orderBookingClient.request<{ potential: { potential: any[] } }>(
|
||||||
|
'POST',
|
||||||
|
'/api/papi2/potential-mining',
|
||||||
|
payload,
|
||||||
|
{ 'TemplateID': '146' }
|
||||||
|
);
|
||||||
|
|
||||||
|
const rawPotential = response.potential?.potential || [];
|
||||||
|
const mappedPotential = rawPotential.map((row: any) => {
|
||||||
|
const cat = row.product_category || row.product_category_ || row.category;
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
product_category_: cat,
|
||||||
|
product_category: cat,
|
||||||
|
productcategory: cat,
|
||||||
|
category: cat,
|
||||||
|
product_category_1: cat
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
setMiningPrefill({ potential: mappedPotential });
|
||||||
|
setActiveActivity({ id: ORDER_BOOKING.activities.POTENTIAL_MINING.uid, name: 'Potential Mining' });
|
||||||
|
} catch (e: any) {
|
||||||
|
alert("Failed to fetch potential mining data: " + (e.message || "Unknown error"));
|
||||||
|
} finally {
|
||||||
|
setMiningLoading(false);
|
||||||
|
setIsFabOpen(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<OrdersView
|
<OrdersView
|
||||||
refreshKey={refreshKey}
|
refreshKey={refreshKey}
|
||||||
onRowClick={(row) => {
|
onRowClick={(row) => {
|
||||||
|
setSelectedRow(row);
|
||||||
const id = row.instance_id as number | string | undefined;
|
const id = row.instance_id as number | string | undefined;
|
||||||
if (id != null) navigate(`/orders/${id}`);
|
if (id != null) navigate(`/orders/${id}`);
|
||||||
}}
|
}}
|
||||||
@ -56,11 +108,66 @@ export function OrdersPage() {
|
|||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
open={instanceId != null}
|
open={instanceId != null}
|
||||||
onClose={() => navigate(`/orders`)}
|
onClose={() => { navigate(`/orders`); setIsFabOpen(false); }}
|
||||||
title={instanceId != null ? `Order #${instanceId}` : undefined}
|
title={instanceId != null ? `Order #${instanceId}` : undefined}
|
||||||
width="lg"
|
width="lg"
|
||||||
>
|
>
|
||||||
{instanceId != null && <OrderDetail instanceId={instanceId} />}
|
{instanceId != null && (
|
||||||
|
<>
|
||||||
|
<OrderDetail instanceId={instanceId} />
|
||||||
|
<div className="absolute bottom-6 right-6 flex flex-col items-end gap-3 z-50">
|
||||||
|
{isFabOpen && (
|
||||||
|
<div className="flex flex-col gap-2 bg-white p-3 rounded-sm shadow-xl border border-border-subtle animate-in fade-in slide-in-from-bottom-2">
|
||||||
|
<Button size="sm" variant="secondary" onClick={handlePotentialMiningClick} disabled={miningLoading}>
|
||||||
|
{miningLoading ? 'Loading...' : 'Potential Mining'}
|
||||||
|
</Button>
|
||||||
|
{(() => {
|
||||||
|
const stateName = String(selectedRow?.current_state_name || selectedRow?.current_state_name_ || selectedRow?.current_state || selectedRow?.status || '').toLowerCase();
|
||||||
|
if (stateName.includes('ordered') || stateName === 'ordered') {
|
||||||
|
return (
|
||||||
|
<Button size="sm" onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
setActiveActivity({ id: ORDER_BOOKING.activities.EDIT_ORDER.uid, name: 'Edit Order' });
|
||||||
|
setIsFabOpen(false);
|
||||||
|
}}>
|
||||||
|
Edit Order
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
} else if (stateName.includes('productive')) {
|
||||||
|
return (
|
||||||
|
<Button size="sm" onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
setActiveActivity({ id: ORDER_BOOKING.activities.PLACE_ORDER.uid, name: 'Place Order' });
|
||||||
|
setIsFabOpen(false);
|
||||||
|
}}>
|
||||||
|
Place Order
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Button size="sm" onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
setActiveActivity({ id: ORDER_BOOKING.activities.PLACE_ORDER.uid, name: 'Place Order' });
|
||||||
|
setIsFabOpen(false);
|
||||||
|
}}>
|
||||||
|
Place Order
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Button size='fab'
|
||||||
|
className="rounded-full shadow-xl flex items-center justify-center !p-0"
|
||||||
|
onClick={() => setIsFabOpen(!isFabOpen)}
|
||||||
|
>
|
||||||
|
<Plus size={24} className={`transition-transform duration-200 ${isFabOpen ? "rotate-45" : ""}`} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
@ -75,6 +182,7 @@ export function OrdersPage() {
|
|||||||
activityId={activeActivity.id}
|
activityId={activeActivity.id}
|
||||||
instanceId={instanceId}
|
instanceId={instanceId}
|
||||||
ignorePrefill={activeActivity.id === ORDER_BOOKING.activities.PLACE_ORDER.uid}
|
ignorePrefill={activeActivity.id === ORDER_BOOKING.activities.PLACE_ORDER.uid}
|
||||||
|
customPrefillData={activeActivity.id === ORDER_BOOKING.activities.POTENTIAL_MINING.uid ? miningPrefill : undefined}
|
||||||
onSuccess={() => {
|
onSuccess={() => {
|
||||||
setActiveActivity(null);
|
setActiveActivity(null);
|
||||||
setRefreshKey(k => k + 1);
|
setRefreshKey(k => k + 1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user