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

SCRUM-47 Basic information about Carpool Group #128

Merged
merged 51 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
17d086a
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
b33bead
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
9bedbd1
Minor changes on rider side group page when in group
sinhaaaryan Nov 20, 2024
dabc6dd
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
549694c
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
f87d963
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
6fd35e8
Minor changes on rider side group page when in group
sinhaaaryan Nov 20, 2024
2519c6e
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
5304a86
rebased off staging
sinhaaaryan Nov 21, 2024
b731e4b
rebased changes from email.ts
sinhaaaryan Nov 21, 2024
e1a280a
FTUE tracking + view route event fix
matherg Nov 22, 2024
b5ad2ff
Merge pull request #130 from sandboxnu/mixpanelFTUE
sinhaaaryan Nov 22, 2024
4ce2c52
Changes per review
sinhaaaryan Nov 25, 2024
6a7e4cd
Admin dashboard initial setup
matherg Nov 25, 2024
6e2db62
Admin setup and perm management done
matherg Nov 26, 2024
cece952
hide overflow
matherg Nov 26, 2024
6d9859e
missed file
matherg Nov 26, 2024
317b07f
Merge pull request #132 from sandboxnu/adminInitial
matherg Nov 26, 2024
f546506
Logic improvement for admin users + tooltip
matherg Nov 26, 2024
1a00643
Admin Charts
matherg Nov 26, 2024
75ab43d
Both charts fully implemented
matherg Nov 27, 2024
a6e5432
Slider step by week
matherg Nov 27, 2024
20ad307
End range of slider inclusive
matherg Nov 27, 2024
11b51b7
Merge pull request #133 from sandboxnu/adminData
matherg Nov 27, 2024
c458bf5
Inactive user settings, main is overwhelmed otherwise
matherg Nov 27, 2024
69860fb
Added toast popup, blocks drivers from switching roles in a group
matherg Dec 2, 2024
f9f6f20
Merge pull request #136 from sandboxnu/SCRUM-125
sinhaaaryan Dec 3, 2024
86b3622
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
d596dd3
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
c9151bd
Minor changes on rider side group page when in group
sinhaaaryan Nov 20, 2024
f0fe5c6
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
fd1d453
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
11c2436
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
44913a6
Changes per review
sinhaaaryan Nov 25, 2024
d6e99d5
Merge branch 'SCRUM-47' of https://github.com/sandboxnu/nucarpool int…
sinhaaaryan Dec 3, 2024
10de778
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
e771ec1
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
85fcdf0
Minor changes on rider side group page when in group
sinhaaaryan Nov 20, 2024
6eed630
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
740b137
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
2135e50
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
0138d1a
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
e159d15
rebased changes from email.ts
sinhaaaryan Nov 21, 2024
17544c6
Changes per review
sinhaaaryan Nov 25, 2024
f040fd5
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
501c5de
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
35b4070
Fixed tsc + lint errors
sinhaaaryan Nov 21, 2024
03ab954
Backend logic working, now just frontend edits remaining
sinhaaaryan Nov 18, 2024
679d9bd
Various changes to group page + changes to DB to support more charact…
sinhaaaryan Nov 19, 2024
9941d33
Merge branch 'SCRUM-47' of https://github.com/sandboxnu/nucarpool int…
sinhaaaryan Dec 3, 2024
6a8e445
rebased off schema
sinhaaaryan Dec 3, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- AlterTable
ALTER TABLE `conversation` ADD COLUMN `dateCreated` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- AlterTable
ALTER TABLE `group` ADD COLUMN `dateCreated` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);

-- AlterTable
ALTER TABLE `user` ADD COLUMN `coop_end_date` DATE NULL,
ADD COLUMN `coop_start_date` DATE NULL,
ADD COLUMN `dateCreated` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `dateModified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `group_message` TEXT NULL,
MODIFY `role` ENUM('RIDER', 'DRIVER', 'VIEWER') NOT NULL DEFAULT 'VIEWER';
2 changes: 2 additions & 0 deletions prisma/migrations/20241119202706_add_text_type/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `group` MODIFY `message` TEXT NOT NULL;
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ model Message {
// Represents a group of users
model CarpoolGroup {
id String @id @default(cuid()) // primary key
message String
message String @db.Text
users User[]
dateCreated DateTime @default(now())

Expand Down Expand Up @@ -163,6 +163,7 @@ model User {
Message Message[]
dateCreated DateTime @default(now())
dateModified DateTime @default(now()) @updatedAt
groupMessage String? @map("group_message") @db.Text

@@index([carpoolId])
@@map(name: "user")
Expand Down
79 changes: 69 additions & 10 deletions src/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,76 @@ const GroupBody = ({
onClose: () => void;
}) => {
return !curUser?.carpoolId ? (
<NoGroupInfo role={curUser.role} />
<NoGroupInfo role={curUser.role} onClose={onClose} />
) : (
<GroupInfo curUser={curUser} onClose={onClose} />
);
};

interface NoGroupInfoProps {
role: Role;
onClose: () => void;
}

const NoGroupInfo = ({ role }: NoGroupInfoProps) => {
const text =
role === Role.VIEWER
? "You are in Viewer mode, switch to Rider or Driver to join a group"
: "You are not currently part of a carpool group";
const NoGroupInfo = ({ role, onClose }: NoGroupInfoProps) => {
const utils = trpc.useContext();
const { data: user } = trpc.user.me.useQuery();
const [groupMessage, setGroupMessage] = useState(user?.groupMessage ?? "");
const { mutate: updateUserMessage } = trpc.user.groups.updateUserMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the user.me query
utils.user.me.invalidate();
},
});

useEffect(() => {
if (user?.groupMessage) {
setGroupMessage(user.groupMessage);
}
}, [user]);

const handleMessageSubmit = async () => {
if (user?.id && role === "DRIVER") {
await updateUserMessage({ message: groupMessage });
}
};

return (
<div className="flex flex-grow items-center justify-center text-xl font-light">
{text}
<div className="flex flex-col">
{role === Role.VIEWER ? (
<div className="flex flex-grow items-center justify-center text-xl font-light">
You are in Viewer mode, switch to Rider or Driver to join a group
</div>
) : (
<>
{role === "DRIVER" && (
<div className="mx-20 flex flex-col py-1 mb-8">
<div className="my-1 text-xs italic text-slate-400">
Below, share any information that you would like riders joining you your Carpool to know. You can indicate when you generally like to be leaving your place, what your preferred method of communication is, what your preference is to split gas and what your Carpool vibe will be like.
</div>
<div className="flex flex-row gap-2">
<textarea
className="form-input min-h-[50px] flex-grow resize-none rounded-md py-2 shadow-sm"
value={groupMessage}
onChange={(e) => setGroupMessage(e.target.value)}
/>
<button
className="w-[150px] rounded-md bg-red-700 py-2 text-white h-full"
onClick={async () => {
await handleMessageSubmit();
onClose();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClose() doesn't seem to do anything. After pressing submit, there should be some indication of success. (could be loading symbol, popup, or a text display under the text box showing the current message)

}}
>
Submit
</button>
</div>
</div>
)}
<div className="flex flex-grow items-center justify-center text-xl font-light">
You are not currently part of a carpool group
</div>
</>
)}
</div>
);
};
Expand All @@ -77,11 +129,16 @@ const GroupInfo = ({
curUser: User;
onClose: () => void;
}) => {
const utils = trpc.useContext();
const { data: group } = trpc.user.groups.me.useQuery();
const users = group?.users ?? [];
const [groupMessage, setGroupMessage] = useState(group?.message ?? "");
const { mutate: updateMessage } =
trpc.user.groups.updateMessage.useMutation();
const { mutate: updateMessage } = trpc.user.groups.updateMessage.useMutation({
onSuccess: () => {
// Invalidate and refetch the groups.me query
utils.user.groups.me.invalidate();
},
});

useEffect(() => {
setGroupMessage(group?.message ?? "");
Expand Down Expand Up @@ -117,6 +174,8 @@ const GroupInfo = ({
</div>
) : (
<div className="mx-16 flex flex-col py-1">
<div className="text-center">Carpool Information from Driver</div>
<br/>
<p className="flex-1 justify-center rounded-md border px-3 py-2 text-center text-sm shadow-sm">
{groupMessage != ""
? groupMessage
Expand Down
25 changes: 21 additions & 4 deletions src/server/router/user/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ export const groupsRouter = router({
where: { id: input.driverId },
});

if (driver?.seatAvail === 0) {
if (!driver) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Driver does not have space available in their car",
code: "NOT_FOUND",
message: "Driver not found",
});
}

const group = await ctx.prisma.carpoolGroup.create({
data: {
users: {
connect: { id: input.driverId },
},
message: "",
message: driver.groupMessage || "",
},
});

const nGroup = await ctx.prisma.carpoolGroup.update({
where: { id: group.id },
data: {
Expand Down Expand Up @@ -207,4 +209,19 @@ export const groupsRouter = router({
});
return updatedGroup;
}),
updateUserMessage: protectedRouter
.input(
z.object({
message: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const updatedUser = await ctx.prisma.user.update({
where: { id: ctx.session.user?.id },
data: {
groupMessage: input.message,
},
});
return updatedUser;
}),
});
Loading