Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ia tickets 27 72 user preferences #92

Merged
merged 27 commits into from
Sep 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
35bc92b
Added layout and dash control panel
ialej001 Sep 3, 2022
d325953
Merge branch 'development' into feature/ia-tickets-27-72-user-prefere…
ialej001 Sep 4, 2022
32121e2
added preferences router and procedures
ialej001 Sep 5, 2022
8183c7b
merged preferences router into trpc
ialej001 Sep 5, 2022
cce611d
added preferences query and fixed pref mutation
ialej001 Sep 5, 2022
40c89ad
location prefs load on render and now update db
ialej001 Sep 5, 2022
ca26e76
Merge branch 'development' into feature/ia-tickets-27-72-user-prefere…
ialej001 Sep 6, 2022
83b3614
fixed typo
ialej001 Sep 6, 2022
f710f9c
unit pref save/load on render
ialej001 Sep 6, 2022
c5f6e04
form close/cancel resets, save persists to db
ialej001 Sep 6, 2022
4527cbd
removed head element
ialej001 Sep 6, 2022
fb83aef
feat: set primary vehicle
ialej001 Sep 6, 2022
b25f439
fixed trpc endpoint
ialej001 Sep 6, 2022
5debada
primary button now rerenders on click
ialej001 Sep 6, 2022
34fd602
vehicles refetch on new vehicle submit
ialej001 Sep 6, 2022
f752e52
cleaned up modal appearance
ialej001 Sep 6, 2022
f95f67b
feat: delete car and remove primaryId if required
ialej001 Sep 6, 2022
f601671
updated vehicle tile styles
ialej001 Sep 6, 2022
9ac8a50
styling: added responsiveness
ialej001 Sep 6, 2022
1a9a9a3
moved preferences back into /account
ialej001 Sep 6, 2022
82045f0
added missing unauth error throw
ialej001 Sep 6, 2022
28069d8
updated styling
ialej001 Sep 6, 2022
b9e052d
render empty message on no saved cars
ialej001 Sep 6, 2022
b0ffc8e
added location save feedback
ialej001 Sep 7, 2022
b07f8bd
added unit preference saved feedback
ialej001 Sep 7, 2022
e3d86b2
updated logout button style and function
ialej001 Sep 7, 2022
6826a3f
redirects back to login with no session
ialej001 Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
vehicles refetch on new vehicle submit
ialej001 committed Sep 6, 2022
commit 34fd6025cf6af29170bee11f2de190c1580a81c7
15 changes: 11 additions & 4 deletions src/components/Account/Preferences/NewVehicleModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Button, Label, Modal } from 'flowbite-react';
import Head from 'next/head';
import React, { useEffect, useState } from 'react';
import SelectSearch, {
fuzzySearch,
@@ -26,14 +25,22 @@ const NewVehicleModal = ({ show, toggleModal }: NewVehicleModalProps) => {
SelectedOptionValue | SelectedOptionValue[] | string
>('');

const utils = trpc.useContext();

const makes = trpc.useQuery(['vehicle.get-vehicle-makes']);
const models = trpc.useQuery([
'vehicle.get-vehicle-models',
selectedVehicleMake as string,
]);
const { mutate: mutateVehicle } = trpc.useMutation([
'preferences.add-user-vehicle',
]);

const { mutate: mutateVehicle } = trpc.useMutation(
['preferences.add-user-vehicle'],
{
onSuccess() {
utils.refetchQueries(['preferences.get-user-vehicles'], {active: true, exact: true, inactive: true})
},
}
);

useEffect(() => {
if (!makes.isLoading && makes.data) {
13 changes: 10 additions & 3 deletions src/server/router/preferences.router.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ import {
updateUserLocationSchema,
updateUserPrimaryVehicleSchema,
updateUserUnitPreferenceSchema,
Vehicles,
vehicleSchema,
} from '../../schema/preferences.schema';
import { createRouter } from './context';

@@ -161,14 +159,23 @@ export const preferencesRouter = createRouter()
const user = ctx.session?.user;

if (user) {
ctx.prisma.vehicle
const vehicle = await ctx.prisma.vehicle
.create({
data: {
...input,
userId: user.id,
},
select: {
id: true,
vehicle_make: true,
vehicle_model: true,
vehicle_model_id: true,
vehicle_year: true,
},
})
.then((response) => response);

return vehicle;
}
},
})