mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-05-03 08:29:50 -04:00
add ability to specify if you can drive or not
This commit is contained in:
parent
9fd6daa826
commit
785934b863
|
@ -1,4 +1,4 @@
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
import { green, lightgrey } from '../../lib/colors';
|
import { green, lightgrey } from '../../lib/colors';
|
||||||
import getPlaceDetails from '../../lib/getPlaceDetails';
|
import getPlaceDetails from '../../lib/getPlaceDetails';
|
||||||
import { addOrUpdateEventSignup, removeEventSignup } from '../api';
|
import { addOrUpdateEventSignup, removeEventSignup } from '../api';
|
||||||
|
@ -12,10 +12,14 @@ import EventSignups from './EventSignups';
|
||||||
export default function EventInterestForm() {
|
export default function EventInterestForm() {
|
||||||
const event = useMutableEvent();
|
const event = useMutableEvent();
|
||||||
const me = useMe() || { id: 0, name: '' };
|
const me = useMe() || { id: 0, name: '' };
|
||||||
|
const placeIdRef = useRef<string | null>(null);
|
||||||
|
const canDriveRef = useRef(false);
|
||||||
|
|
||||||
const updateSignup = useCallback(
|
const updateSignup = useCallback(async () => {
|
||||||
async (placeId: string | null) => {
|
const placeId = placeIdRef.current;
|
||||||
await addOrUpdateEventSignup(event.id, placeId);
|
const canDrive = canDriveRef.current;
|
||||||
|
|
||||||
|
await addOrUpdateEventSignup(event.id, placeIdRef.current, canDrive);
|
||||||
|
|
||||||
if (placeId) {
|
if (placeId) {
|
||||||
const details = await getPlaceDetails(placeId);
|
const details = await getPlaceDetails(placeId);
|
||||||
|
@ -24,6 +28,7 @@ export default function EventInterestForm() {
|
||||||
user: { id: me.id, name: me.name },
|
user: { id: me.id, name: me.name },
|
||||||
placeId,
|
placeId,
|
||||||
...details,
|
...details,
|
||||||
|
canDrive,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
event.signups[me.id] = {
|
event.signups[me.id] = {
|
||||||
|
@ -32,11 +37,10 @@ export default function EventInterestForm() {
|
||||||
latitude: null,
|
latitude: null,
|
||||||
longitude: null,
|
longitude: null,
|
||||||
formattedAddress: null,
|
formattedAddress: null,
|
||||||
|
canDrive,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
}, [event.id, event.signups, me.id, me.name]);
|
||||||
[event.id, event.signups, me.id, me.name]
|
|
||||||
);
|
|
||||||
|
|
||||||
const removeSignup = useCallback(async () => {
|
const removeSignup = useCallback(async () => {
|
||||||
await removeEventSignup(event.id);
|
await removeEventSignup(event.id);
|
||||||
|
@ -48,10 +52,19 @@ export default function EventInterestForm() {
|
||||||
|
|
||||||
const interested = !!event.signups[me.id];
|
const interested = !!event.signups[me.id];
|
||||||
|
|
||||||
|
const canDrive = !!event.signups[me.id]?.canDrive;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UIButton
|
<UIButton
|
||||||
onClick={interested ? () => removeSignup() : () => updateSignup(null)}
|
onClick={
|
||||||
|
interested
|
||||||
|
? () => removeSignup()
|
||||||
|
: () => {
|
||||||
|
placeIdRef.current = null;
|
||||||
|
updateSignup();
|
||||||
|
}
|
||||||
|
}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: interested ? green : lightgrey,
|
backgroundColor: interested ? green : lightgrey,
|
||||||
color: interested ? 'white' : 'black',
|
color: interested ? 'white' : 'black',
|
||||||
|
@ -62,10 +75,24 @@ export default function EventInterestForm() {
|
||||||
</UIButton>
|
</UIButton>
|
||||||
{interested && (
|
{interested && (
|
||||||
<>
|
<>
|
||||||
|
<UIButton
|
||||||
|
onClick={() => {
|
||||||
|
canDriveRef.current = !canDriveRef.current;
|
||||||
|
updateSignup();
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
backgroundColor: canDrive ? green : lightgrey,
|
||||||
|
color: canDrive ? 'white' : 'black',
|
||||||
|
transition: 'color 0.2s, background-color 0.2s',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{canDrive ? 'Can drive' : "Can't drive"}
|
||||||
|
</UIButton>
|
||||||
<UIPlacesAutocomplete
|
<UIPlacesAutocomplete
|
||||||
placeholder="Pickup and dropoff location"
|
placeholder="Pickup and dropoff location"
|
||||||
onSelected={(_address, placeId) => {
|
onSelected={(_address, placeId) => {
|
||||||
updateSignup(placeId);
|
placeIdRef.current = placeId;
|
||||||
|
updateSignup();
|
||||||
}}
|
}}
|
||||||
style={
|
style={
|
||||||
event.signups[me.id]?.placeId != null
|
event.signups[me.id]?.placeId != null
|
||||||
|
|
|
@ -70,9 +70,10 @@ export async function getEventSignups(
|
||||||
|
|
||||||
export async function addOrUpdateEventSignup(
|
export async function addOrUpdateEventSignup(
|
||||||
eventId: number,
|
eventId: number,
|
||||||
placeId: string | null
|
placeId: string | null,
|
||||||
|
canDrive: boolean
|
||||||
) {
|
) {
|
||||||
await post(`/events/${eventId}/signup`, { placeId });
|
await post(`/events/${eventId}/signup`, { placeId, canDrive });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeEventSignup(eventId: number) {
|
export async function removeEventSignup(eventId: number) {
|
||||||
|
|
|
@ -92,6 +92,7 @@ export type IEventSignupComplete = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
canDrive: boolean;
|
||||||
placeId: string;
|
placeId: string;
|
||||||
formattedAddress: string;
|
formattedAddress: string;
|
||||||
latitude: number;
|
latitude: number;
|
||||||
|
@ -103,6 +104,7 @@ export type IEventSignupIncomplete = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
canDrive: boolean;
|
||||||
placeId: null;
|
placeId: null;
|
||||||
formattedAddress: null;
|
formattedAddress: null;
|
||||||
latitude: null;
|
latitude: null;
|
||||||
|
|
|
@ -47,8 +47,6 @@ export default function estimateOptimalPath<
|
||||||
|
|
||||||
const newWaypoints = sequence.slice(1, sequence.length - 1);
|
const newWaypoints = sequence.slice(1, sequence.length - 1);
|
||||||
|
|
||||||
console.log({ sequence, path });
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: {
|
path: {
|
||||||
from,
|
from,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user