Fix dispatches
This commit is contained in:
parent
f059ca37da
commit
1a2d143c4f
@ -83,8 +83,6 @@ const headers = {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getMakers = async () => {
|
const getMakers = async () => {
|
||||||
const url = `${API_URL}/api/makers`
|
const url = `${API_URL}/api/makers`
|
||||||
console.log("Fetching url:", url)
|
console.log("Fetching url:", url)
|
||||||
@ -129,6 +127,7 @@ const getDispatches = async () => {
|
|||||||
const response = await axios.get(url);
|
const response = await axios.get(url);
|
||||||
|
|
||||||
const dispatches:Dispatch[] = response.data.docs;
|
const dispatches:Dispatch[] = response.data.docs;
|
||||||
|
|
||||||
console.log(`Fetch result from ${url}`, dispatches)
|
console.log(`Fetch result from ${url}`, dispatches)
|
||||||
return dispatches;
|
return dispatches;
|
||||||
|
|
||||||
@ -137,11 +136,21 @@ const getDispatches = async () => {
|
|||||||
const useGetDispatches = () => {
|
const useGetDispatches = () => {
|
||||||
return useQuery<Dispatch[]>({
|
return useQuery<Dispatch[]>({
|
||||||
queryFn: () => getDispatches(),
|
queryFn: () => getDispatches(),
|
||||||
queryKey: ['retailers'],
|
queryKey: ['dispatches'],
|
||||||
enabled: true
|
enabled: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Payload longitude and latitude are mislabeled in payload (lol)
|
||||||
|
const locationSwitcharoo = (location: number[]) => {
|
||||||
|
if(location.length === 2) {
|
||||||
|
const correctedLocation = [location[1], location[0]]
|
||||||
|
return correctedLocation;
|
||||||
|
}
|
||||||
|
console.error("locationSwitcharoo: Location array malformed")
|
||||||
|
return location
|
||||||
|
}
|
||||||
|
|
||||||
export const KiosMap = () => {
|
export const KiosMap = () => {
|
||||||
|
|
||||||
const { data: makers, isLoading: isLoadingMakers } = useGetMakers();
|
const { data: makers, isLoading: isLoadingMakers } = useGetMakers();
|
||||||
@ -176,12 +185,12 @@ export const KiosMap = () => {
|
|||||||
attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{makers &&
|
{(makers && !isLoadingMakers) &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{makers.map((maker: any, index: number) => (
|
{makers.map((maker: any, index: number) => (
|
||||||
<Marker
|
<Marker
|
||||||
key={index}
|
key={index}
|
||||||
position={[maker.location[0], maker.location[1]]}
|
position={[locationSwitcharoo(maker.location)[0], locationSwitcharoo(maker.location)[1]]}
|
||||||
icon={blackDotIcon}
|
icon={blackDotIcon}
|
||||||
>
|
>
|
||||||
<Popup>{maker.name}</Popup>
|
<Popup>{maker.name}</Popup>
|
||||||
@ -190,12 +199,12 @@ export const KiosMap = () => {
|
|||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
}
|
||||||
|
|
||||||
{retailers &&
|
{(retailers && !isLoadingRetailers) &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{retailers.map((retailer: any, index: number) => (
|
{retailers.map((retailer: any, index: number) => (
|
||||||
<Marker
|
<Marker
|
||||||
key={index}
|
key={index}
|
||||||
position={[retailer.location[0], retailer.location[1]]}
|
position={[locationSwitcharoo(retailer.location)[0], locationSwitcharoo(retailer.location)[1]]}
|
||||||
icon={blackDotIcon}
|
icon={blackDotIcon}
|
||||||
>
|
>
|
||||||
<Popup>{retailer.name}</Popup>
|
<Popup>{retailer.name}</Popup>
|
||||||
@ -204,11 +213,15 @@ export const KiosMap = () => {
|
|||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
}
|
||||||
|
|
||||||
{dispatches &&
|
{(dispatches && !isLoadingDispatches) &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{dispatches.map((dispatch: any, index: number) => {
|
{dispatches.map((dispatch: any, index: number) => {
|
||||||
const start = dispatch.maker.location;
|
|
||||||
const end = dispatch.retailer.location;
|
if(dispatch.maker && dispatch.retailer) {
|
||||||
|
|
||||||
|
const start = locationSwitcharoo(dispatch.maker.location);
|
||||||
|
const end = locationSwitcharoo(dispatch.retailer.location);
|
||||||
|
|
||||||
|
|
||||||
let productsString = '';
|
let productsString = '';
|
||||||
dispatch.products.forEach((product: any, i: number) => {
|
dispatch.products.forEach((product: any, i: number) => {
|
||||||
@ -222,22 +235,13 @@ export const KiosMap = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
<Marker position={[start[0], start[1]]}
|
|
||||||
icon={blackDotIcon}
|
|
||||||
>
|
|
||||||
<Popup>{dispatch.startingPoint.name}</Popup>
|
|
||||||
</Marker>
|
|
||||||
<Marker position={[end[0], end[1]]}
|
|
||||||
icon={blackDotIcon}
|
|
||||||
>
|
|
||||||
<Popup>{dispatch.endPoint.name}</Popup>
|
|
||||||
</Marker>
|
|
||||||
<Polyline
|
<Polyline
|
||||||
positions={[[start[0], start[1]], [end[0], end[1]]]}
|
positions={[[start[0], start[1]], [end[0], end[1]]]}
|
||||||
color="#000"
|
color="#000"
|
||||||
dashArray={myDashArray} />
|
dashArray={myDashArray} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
})}
|
})}
|
||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,12 @@ export interface Courier {
|
|||||||
}
|
}
|
||||||
export interface Dispatch {
|
export interface Dispatch {
|
||||||
id: string;
|
id: string;
|
||||||
|
code: string;
|
||||||
products: string[] | Product[];
|
products: string[] | Product[];
|
||||||
courier?: string | Courier;
|
courier?: string | Courier;
|
||||||
maker?: string | Maker;
|
maker: string | Maker;
|
||||||
retailer?: string | Retailer;
|
retailer: string | Retailer;
|
||||||
status: ('requested' | 'accepted' | 'archived')[];
|
status: 'requested' | 'accepted' | 'archived';
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,20 @@ import { CollectionConfig } from 'payload/types';
|
|||||||
const Dispatches: CollectionConfig = {
|
const Dispatches: CollectionConfig = {
|
||||||
slug: 'dispatches',
|
slug: 'dispatches',
|
||||||
admin: {
|
admin: {
|
||||||
useAsTitle: 'dispatchesCode',
|
useAsTitle: 'code',
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
read: () => true,
|
read: () => true,
|
||||||
},
|
},
|
||||||
fields: [
|
fields: [
|
||||||
// {
|
{
|
||||||
// name: 'dispatchesCode',
|
name: 'code',
|
||||||
// type: 'text',
|
type: 'text',
|
||||||
// required: false,
|
required: true,
|
||||||
// },
|
maxLength: 20,
|
||||||
|
unique: true,
|
||||||
|
label: "Code, a unique name for the dispatch"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'products',
|
name: 'products',
|
||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
@ -33,19 +36,19 @@ const Dispatches: CollectionConfig = {
|
|||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
relationTo: 'makers',
|
relationTo: 'makers',
|
||||||
hasMany: false,
|
hasMany: false,
|
||||||
required: false
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'retailer',
|
name: 'retailer',
|
||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
relationTo: 'retailers',
|
relationTo: 'retailers',
|
||||||
hasMany: false,
|
hasMany: false,
|
||||||
required: false
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'status',
|
name: 'status',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
hasMany: true,
|
hasMany: false,
|
||||||
required: true,
|
required: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ import { CollectionConfig } from 'payload/types';
|
|||||||
const Products: CollectionConfig = {
|
const Products: CollectionConfig = {
|
||||||
slug: 'products',
|
slug: 'products',
|
||||||
admin: {
|
admin: {
|
||||||
useAsTitle: 'productTitle',
|
useAsTitle: 'title',
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
read: () => true,
|
read: () => true,
|
||||||
|
Loading…
Reference in New Issue
Block a user