Files
webapp/app/composables/useTeamOrders.ts
Ruslan Bakiev 53904ead05
All checks were successful
Build Docker Image / build (push) Successful in 3m38s
Fix: offers map coords, map position, orders filter, select-location layout
2026-01-08 13:01:54 +07:00

100 lines
2.9 KiB
TypeScript

const items = ref<any[]>([])
const isLoading = ref(false)
const isInitialized = ref(false)
export function useTeamOrders() {
const { t } = useI18n()
const { execute } = useGraphQL()
const filters = computed(() => [
{ id: 'all', label: t('ordersList.filters.all') },
{ id: 'pending', label: t('ordersList.filters.pending') },
{ id: 'processing', label: t('ordersList.filters.processing') },
{ id: 'in_transit', label: t('ordersList.filters.in_transit') },
{ id: 'delivered', label: t('ordersList.filters.delivered') }
])
const selectedFilter = ref('all')
const filteredItems = computed(() => {
if (selectedFilter.value === 'all') return items.value
return items.value.filter(order => order.status === selectedFilter.value)
})
const routesForMap = computed(() =>
filteredItems.value
.map(order => ({
uuid: order.uuid,
name: order.name,
status: order.status,
stages: (order.stages || [])
.filter((s: any) => s.stageType === 'transport' && s.sourceLatitude && s.sourceLongitude && s.destinationLatitude && s.destinationLongitude)
.map((s: any) => ({
fromLat: s.sourceLatitude,
fromLon: s.sourceLongitude,
toLat: s.destinationLatitude,
toLon: s.destinationLongitude,
fromName: s.sourceLocationName,
toName: s.destinationLocationName,
transportType: s.transportType
}))
}))
.filter(order => order.stages.length > 0)
)
const load = async () => {
isLoading.value = true
try {
const { GetTeamOrdersDocument } = await import('~/composables/graphql/team/orders-generated')
const data = await execute(GetTeamOrdersDocument, {}, 'team', 'orders')
items.value = data?.getTeamOrders || []
isInitialized.value = true
} catch (e) {
console.error('Failed to load orders', e)
} finally {
isLoading.value = false
}
}
const init = async () => {
if (!isInitialized.value && items.value.length === 0) {
await load()
}
}
const getStatusVariant = (status: string) => {
const variants: Record<string, string> = {
pending: 'warning',
processing: 'primary',
in_transit: 'info',
delivered: 'success',
cancelled: 'error'
}
return variants[status] || 'muted'
}
const getStatusText = (status: string) => {
const texts: Record<string, string> = {
pending: t('ordersDetail.status.pending'),
processing: t('ordersDetail.status.processing'),
in_transit: t('ordersDetail.status.in_transit'),
delivered: t('ordersDetail.status.delivered'),
cancelled: t('ordersDetail.status.cancelled')
}
return texts[status] || status || t('ordersDetail.status.unknown')
}
return {
items,
filteredItems,
isLoading,
filters,
selectedFilter,
routesForMap,
load,
init,
getStatusVariant,
getStatusText
}
}