Skip to content

Commit 6bce579

Browse files
committed
☑️ Fixes typescript failures
1 parent 8cc8e1f commit 6bce579

File tree

8 files changed

+28
-31
lines changed

8 files changed

+28
-31
lines changed

pages/reset_password.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import axios from 'axios';
2-
import { Alert, Button, Label, TextInput } from 'flowbite-react';
2+
import { Alert, Button, TextInput } from 'flowbite-react';
33
import { Field, Form, Formik, FormikValues } from 'formik';
44
import { GetServerSideProps, NextPage } from 'next';
55
import { useRouter } from 'next/router';
66
import React, { useState } from 'react';
7+
import { useToasts } from '../src/components/contexts/ToastContext';
78
import { API_URL } from '../src/config';
89
import { showErrors } from '../src/utils/viewHelpers';
910

@@ -27,6 +28,7 @@ export const getServerSideProps: GetServerSideProps = async ({ query }) => {
2728
const Reset: NextPage<{ token: string }> = ({ token }) => {
2829
const [errors, setErrors] = useState();
2930
const router = useRouter();
31+
const { addToast } = useToasts();
3032

3133
return (
3234
<section className="bg-gray-50 dark:bg-gray-900">
@@ -38,10 +40,15 @@ const Reset: NextPage<{ token: string }> = ({ token }) => {
3840
onSubmit={(values) => {
3941
axios
4042
.put(`${API_URL}/users/password`, { user: { ...values } })
41-
.then((res) => {
43+
.then(() => {
4244
router.push('/login');
4345
})
4446
.catch((error) => {
47+
addToast(
48+
error?.response?.data?.toString() ||
49+
'Something went wrong'
50+
);
51+
4552
setErrors(error?.response?.data);
4653
});
4754
}}

pages/trips/[id]/edit.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const ShowTrip: NextPage<{ trip: Trip; google: GoogleAPI }> = ({
157157
experience: ride.experience,
158158
tag_list: ride.tags.join(', '),
159159
youtube: ride.youtube,
160+
photo: ride.photo,
160161
photo_caption: ride.photo_caption,
161162
}}
162163
onSubmit={(values, { setSubmitting }) => {

pages/trips/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import OverlayContainer from '../../src/components/OverlayContainer';
55
import OverlayBubble from '../../src/components/OverlayBubble';
66
import { Trip } from '../../src/types';
77
import { ListTrips } from '../../src/components/ListTrips';
8-
import { PuffLoader } from 'react-spinners';
98
import { getTripsWithQuery } from '../../src/db/trips';
109
import LoadingContainer from '../../src/components/LoadingContainer';
1110
import { AxiosResponse } from 'axios';

pages/trips/new.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const New: NextPage<{ google: GoogleAPI; ipLocation: IpLocation }> = ({
8484
const payload = {
8585
trip: values,
8686
};
87-
const t = createTrip(payload)
87+
createTrip(payload)
8888
.then((res) => {
8989
router.push(`/trips/${res.data.id}/edit`);
9090
return res.data;

src/components/TripCard.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ const TripCard: FC<{ map?: google.maps.Map | null; trip: Trip }> = ({
8282
</div>
8383

8484
<div className="flex items-center justify-between mb-2 align gap-2">
85-
<Link href={`/trips/${trip.id}`}>
85+
<Link href={`/trips/${trip.to_param}`}>
8686
<a>
8787
From {trip.origin?.city} to {trip.destination?.city}
8888
</a>
8989
</Link>
9090
{currentUser && currentUser.username === trip.user.username && (
91-
<Link href={`/trips/${trip.id}/edit`} passHref>
91+
<Link href={`/trips/${trip.to_param}/edit`} passHref>
9292
<Button size="xs">Edit</Button>
9393
</Link>
9494
)}
@@ -145,7 +145,7 @@ const TripCard: FC<{ map?: google.maps.Map | null; trip: Trip }> = ({
145145
</>
146146
)}
147147
</div>
148-
<Link href={`/trips/${trip.id}`}>
148+
<Link href={`/trips/${trip.to_param}`}>
149149
<a className="inline-flex items-center font-medium no-underline text-primary-600 dark:text-primary-500 hover:underline">
150150
Read more
151151
<RightArrow />

src/types/Trip.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type Timestamp = { seconds: number; nanoseconds: number };
1414

1515
export type Trip = {
1616
id: number | string;
17+
to_param: string;
1718
arrival: Date;
1819
departure: Date;
1920
created_at: Date;

src/utils/index.ts

-15
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,3 @@ export const secondsToHumanReadable = (seconds: number) => {
119119
if (minutes) array.push(`${minutes}m`);
120120
return array.join(' ');
121121
};
122-
123-
export const tripUrl = (trip: Trip) => {
124-
const from = trip.origin.city
125-
? trip.origin.city
126-
: trip.origin.name
127-
? trip.origin.name
128-
: `${trip.origin.lat},${trip.destination.lng}`;
129-
const to = trip.destination.city
130-
? trip.destination.city
131-
: trip.destination.name
132-
? trip.destination.name
133-
: `${trip.destination.lat},${trip.destination.lng}`;
134-
135-
return `/trips/${trip.id}-hitchhike-from-${from}-to-${to}`;
136-
};

src/utils/viewHelpers.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,19 @@ export const experiencesForProfile = (experiences: ExperiencesRecord) => {
161161
};
162162

163163
export const showErrors = (errors: Record<string, string[]> | string) => {
164-
if (typeof errors === 'string') return errors;
165-
if (Object.keys(errors).length === 0) return errors;
166-
return Object.keys(errors).map((key) => (
167-
<ul key={key}>
168-
<li>
169-
{key}: {errors[key]?.join(' ')}{' '}
170-
</li>
171-
</ul>
172-
));
164+
if (typeof errors === 'string') return <>errors</>;
165+
if (Object.keys(errors).length === 0) return null;
166+
return (
167+
<>
168+
{Object.keys(errors).map((key) => (
169+
<ul key={key}>
170+
<li>
171+
{key}: {errors[key]?.join(' ')}{' '}
172+
</li>
173+
</ul>
174+
))}
175+
</>
176+
);
173177
};
174178

175179
export const showVehiclesForRides = (rides: Ride[]) =>

0 commit comments

Comments
 (0)