90 lines
3.2 KiB
TypeScript
90 lines
3.2 KiB
TypeScript
import { useNavigate, useParams } from 'react-router-dom';
|
|
import { Modal } from '../components/reusable';
|
|
import { OrdersView } from '../components/rv';
|
|
import { OrderDetail } from '../components/dv';
|
|
import { useState } from 'react';
|
|
|
|
import { ShoppingBag } from 'lucide-react';
|
|
import { DynamicForm } from '../components/forms/DynamicForm';
|
|
import { ORDER_BOOKING } from '../api/config';
|
|
import { orderBookingClient } from '../api/clients';
|
|
|
|
export function OrdersPage() {
|
|
const params = useParams();
|
|
const instanceId = params.instanceId ? Number(params.instanceId) : undefined;
|
|
const navigate = useNavigate();
|
|
const [isCreating, setIsCreating] = useState(false);
|
|
const [createTitle, setCreateTitle] = useState("Place Order");
|
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
const [activeActivity, setActiveActivity] = useState<{ id: string; name: string } | null>(null);
|
|
|
|
return (
|
|
<>
|
|
<OrdersView
|
|
refreshKey={refreshKey}
|
|
onRowClick={(row) => {
|
|
const id = row.instance_id as number | string | undefined;
|
|
if (id != null) navigate(`/orders/${id}`);
|
|
}}
|
|
/>
|
|
|
|
{/* Global Floating Action Button for Place Order */}
|
|
<button
|
|
onClick={() => { setIsCreating(true); setCreateTitle("Place Order"); }}
|
|
className="fixed bottom-24 right-6 w-[60px] h-[60px] bg-[var(--z-bg-primary-400)] rounded-3xl flex items-center justify-center shadow-[0_4px_12px_rgba(var(--z-bg-primary-400-rgb),0.4)] text-white z-40 hover:opacity-90 transition-transform hover:scale-105 active:scale-95 cursor-pointer"
|
|
>
|
|
<ShoppingBag size={24} className="text-white" />
|
|
</button>
|
|
|
|
<Modal
|
|
open={isCreating}
|
|
onClose={() => setIsCreating(false)}
|
|
title={createTitle}
|
|
width="md"
|
|
>
|
|
<DynamicForm
|
|
client={orderBookingClient}
|
|
activityId={ORDER_BOOKING.activities.LOG_VISIT.uid}
|
|
onSuccess={() => {
|
|
setIsCreating(false);
|
|
setRefreshKey(k => k + 1);
|
|
}}
|
|
onCancel={() => setIsCreating(false)}
|
|
onActivityChange={(name) => setCreateTitle(name)}
|
|
/>
|
|
</Modal>
|
|
|
|
<Modal
|
|
open={instanceId != null}
|
|
onClose={() => navigate(`/orders`)}
|
|
title={instanceId != null ? `Order #${instanceId}` : undefined}
|
|
width="lg"
|
|
>
|
|
{instanceId != null && <OrderDetail instanceId={instanceId} />}
|
|
</Modal>
|
|
|
|
<Modal
|
|
open={activeActivity != null}
|
|
onClose={() => setActiveActivity(null)}
|
|
title={activeActivity?.name}
|
|
width="md"
|
|
>
|
|
{activeActivity && instanceId != null && (
|
|
<DynamicForm
|
|
client={orderBookingClient}
|
|
activityId={activeActivity.id}
|
|
instanceId={instanceId}
|
|
ignorePrefill={activeActivity.id === ORDER_BOOKING.activities.PLACE_ORDER.uid}
|
|
onSuccess={() => {
|
|
setActiveActivity(null);
|
|
setRefreshKey(k => k + 1);
|
|
}}
|
|
onCancel={() => setActiveActivity(null)}
|
|
onActivityChange={(name) => setActiveActivity(prev => prev ? { ...prev, name } : null)}
|
|
/>
|
|
)}
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|