Compare commits
8 Commits
0d646c5d6b
...
main
Author | SHA1 | Date | |
---|---|---|---|
8fb18ae000 | |||
0e1d640a42 | |||
ac9b63a33a | |||
ac387d41ad | |||
2654b4a9c4 | |||
f152476d8f | |||
26eb75646b | |||
8473d0d4d6 |
@ -10,10 +10,35 @@ const Couriers: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'name', // required
|
name: 'name',
|
||||||
type: 'text', // required
|
type: 'text',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'startingPoint',
|
||||||
|
label: 'Traveling from',
|
||||||
|
type: 'text', // TODO use geopicker here
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'destination',
|
||||||
|
label: 'Traveling to',
|
||||||
|
type: 'text' // TODO user geopicker here
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'departureDate',
|
||||||
|
label: 'Departure date',
|
||||||
|
type: 'date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'arrivalDate',
|
||||||
|
label: 'Arrival date',
|
||||||
|
type: 'date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'weightAllowance',
|
||||||
|
label: 'Weight Allowance (KG)',
|
||||||
|
type: 'number'
|
||||||
|
}
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,11 +32,35 @@ const Dispatches: CollectionConfig = {
|
|||||||
relationTo: 'retailers',
|
relationTo: 'retailers',
|
||||||
hasMany: false,
|
hasMany: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'typeOfTransportation',
|
||||||
|
type: 'select',
|
||||||
|
hasMany: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Air',
|
||||||
|
value: 'air'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Car',
|
||||||
|
value: 'car'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Train',
|
||||||
|
value: 'train'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Boat',
|
||||||
|
value: 'boat'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'courier',
|
name: 'courier',
|
||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
relationTo: 'couriers',
|
relationTo: 'couriers',
|
||||||
hasMany: false,
|
hasMany: false,
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'timeSensitive',
|
name: 'timeSensitive',
|
||||||
@ -68,4 +92,4 @@ const Dispatches: CollectionConfig = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dispatches;
|
export default Dispatches;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { CollectionConfig } from 'payload/types';
|
import { CollectionConfig } from 'payload/types';
|
||||||
|
import { geoPickerField } from "../customFields/geoPicker/field";
|
||||||
|
|
||||||
const Makers: CollectionConfig = {
|
const Makers: CollectionConfig = {
|
||||||
slug: 'makers',
|
slug: 'makers',
|
||||||
@ -14,6 +15,7 @@ const Makers: CollectionConfig = {
|
|||||||
type: 'text', // required
|
type: 'text', // required
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
//geoPickerField, is a bit broken right now
|
||||||
{
|
{
|
||||||
name: 'location',
|
name: 'location',
|
||||||
type: 'point',
|
type: 'point',
|
||||||
|
@ -24,6 +24,11 @@ const Retailers: CollectionConfig = {
|
|||||||
type: 'relationship', // required
|
type: 'relationship', // required
|
||||||
relationTo: 'products', // required
|
relationTo: 'products', // required
|
||||||
hasMany: true,
|
hasMany: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'salesPoint',
|
||||||
|
type: 'text',
|
||||||
|
label: 'Where do you plan to sell/exhibit products?'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
68
src/customFields/geoPicker/GeoPicker.tsx
Normal file
68
src/customFields/geoPicker/GeoPicker.tsx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { useField } from 'payload/components/forms';
|
||||||
|
|
||||||
|
export const GeoPicker: React.FC<{ path: string }> = ({ path }) => {
|
||||||
|
const { value, setValue } = useField<string>({ path });
|
||||||
|
const [longitude, setLongitude] = React.useState(value[0] || 0);
|
||||||
|
const [latitude, setLatitude] = React.useState(value[1] || 0);
|
||||||
|
const [error, setError] = React.useState("")
|
||||||
|
|
||||||
|
const handleCityEnter = async (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`https://nominatim.openstreetmap.org/search?format=json&q=${e.target.value}`
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
const { lat, lon } = data[0];
|
||||||
|
setLatitude(lat);
|
||||||
|
setLongitude(lon);
|
||||||
|
setValue([lon, lat]);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(e)
|
||||||
|
console.error('Error fetching geolocation:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLatitudeChange = (e) => {
|
||||||
|
setLatitude(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLongitudeChange = (e) => {
|
||||||
|
setLongitude(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className='field-type text'>
|
||||||
|
<label className='field-label'>
|
||||||
|
City
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className='field-name'
|
||||||
|
onKeyDown={handleCityEnter}
|
||||||
|
placeholder="Enter city to get coordinates"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error != "" &&
|
||||||
|
<p>{error}</p>
|
||||||
|
}
|
||||||
|
<div className="field-type point">
|
||||||
|
<ul className='point__wrap'>
|
||||||
|
<li>
|
||||||
|
<label className='field-label'>Location - Longitude</label>
|
||||||
|
<input id="field-longitude-location" type="number" name="location.longitude" value={longitude} onChange={handleLongitudeChange}></input>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label className='field-label'>Location - Latitude</label>
|
||||||
|
<input id="field-latitude-latitude" type="number" name="location.latitude" value={latitude} onChange={handleLatitudeChange}></input>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
12
src/customFields/geoPicker/field.ts
Normal file
12
src/customFields/geoPicker/field.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { PointField } from 'payload/types';
|
||||||
|
import { GeoPicker } from './GeoPicker';
|
||||||
|
|
||||||
|
export const geoPickerField: PointField = {
|
||||||
|
name: 'Location',
|
||||||
|
type: 'point',
|
||||||
|
admin: {
|
||||||
|
components: {
|
||||||
|
Field: GeoPicker,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
Reference in New Issue
Block a user