Skip to content

Commit 2b27b84

Browse files
committed
updated to rebase with main
1 parent 06bc31e commit 2b27b84

File tree

7 files changed

+81
-152
lines changed

7 files changed

+81
-152
lines changed

src/components/Dashboard/DevPostLinkUpload.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import { useState } from "react";
44
import { FaCircleArrowRight } from "react-icons/fa6";
55
import { toast } from "react-toastify";
6-
76
import { client } from "@/app/QueryProvider";
87
import { useMutation, useQuery } from "@tanstack/react-query";
9-
10-
import FormInput from "../UserProfile/FormInput";
118
import { useUser } from "../contexts/UserContext";
129

1310
export default function DevPostLinkUpload() {
@@ -53,13 +50,14 @@ export default function DevPostLinkUpload() {
5350
};
5451
return (
5552
<form onSubmit={handleSubmit} className="flex items-center gap-2 py-2">
56-
<FormInput
57-
name={"devPostLink"}
53+
<input
54+
className={`md:text-md my-2 w-full rounded-full border-2 border-gray-300 bg-gray-100 py-2 ps-3 text-sm text-black `}
5855
placeholder={userTeam?.devPostLink ?? "Awaiting Submission..."}
59-
className="w-full border-2 border-gray-300 bg-gray-100 text-gray-500"
60-
value={devPostLink}
6156
onChange={(e) => setDevPostLink(e.target.value)}
57+
value={devPostLink}
58+
name={devPostLink}
6259
/>
60+
6361
<button type="submit" className="border-1 rounded-full border-red-500 ">
6462
<FaCircleArrowRight color="grey" />
6563
</button>

src/components/Dashboard/GoToFoodTicket.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { FaCircleArrowRight } from "react-icons/fa6";
44
import ParticipantTicketIcon from "@/images/dashboard/ParticipantTicketIcon.png";
55
import Card from "./Card";
66

7-
const href = "/participant/profile/food-ticket";
87
export default function GoToFoodTicket() {
98
return (
109
<Card className="flex h-full flex-row justify-start gap-8">

src/components/UserProfile/FormInput.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/components/UserProfile/TeamForm.tsx

Lines changed: 58 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,91 +24,71 @@ export default function TeamForm({ data, teamMutation }: TeamFormProp) {
2424
const client = generateClient<Schema>();
2525

2626
const { data: teamData, isFetching } = useQuery({
27+
initialData: null,
28+
initialDataUpdatedAt: 0,
2729
queryKey: ["TeamWithMembers"],
2830
queryFn: async () => {
29-
const teamWithMembers = await userTeam?.members();
30-
if (!teamWithMembers) throw new Error("No team members found");
31+
const { data: teamWithMembers } = await client.models.Team.get(
32+
{ id: data.id },
33+
{ selectionSet: ["id", "members.*"] },
34+
);
3135

32-
return teamWithMembers.data;
36+
return teamWithMembers;
3337
},
34-
enabled: !!userTeam,
38+
enabled: !!data,
3539
});
36-
const teamMutation = useMutation({
37-
mutationFn: async () => {
38-
if (!userTeamId) throw new Error("No team ID found");
39-
const { data, errors } = await client.models.User.update({
40-
id: currentUser.id,
41-
teamId: null,
42-
});
43-
console.log(data);
44-
if (errors) throw new Error("TeamID Not found" + errors[0].message);
45-
},
46-
onSuccess: () => {
47-
queryClient.invalidateQueries({
48-
queryKey: ["Team", userTeamId],
49-
});
50-
toast.success("You have left the team");
51-
revalidateUser();
52-
refetchTeam();
53-
},
54-
});
55-
const handleLeaveTeamClick = (e: FormEvent<HTMLFormElement>) => {
56-
e.preventDefault();
57-
teamMutation.mutate();
58-
};
59-
if (!userTeam) return null;
40+
6041
return (
6142
<>
62-
<form className="flex flex-col md:mx-10" onSubmit={handleLeaveTeamClick}>
63-
<FormInput
64-
name={userTeam.id}
65-
disabled
66-
value={userTeam.id}
67-
label={"Team ID"}
68-
/>
69-
<FormInput
70-
name={userTeam.name}
71-
disabled
72-
value={userTeam.name}
73-
label={"Team Name"}
74-
/>
75-
<FormInput
76-
name={"DevPost Link"}
77-
value={userTeam.devPostLink ?? "Awaiting Submission..."}
78-
disabled
79-
placeholder="Awaiting Submission..."
80-
label={"DevPost Link"}
81-
/>
82-
<label>Team Members</label>
83-
<div className="flex flex-col">
84-
{isFetching ? (
85-
<h1 className="md:text-md my-2 rounded-full border-4 border-white bg-white/30 py-2 ps-3 text-sm backdrop-opacity-30 placeholder:text-black">
86-
Loading...
87-
</h1>
88-
) : (
89-
<>
90-
{Array.isArray(teamData) &&
91-
teamData.map((member) => (
92-
<FormInput
93-
key={member.id}
94-
disabled
95-
value={`${member.firstName} ${member.lastName}`}
96-
name={member.id}
97-
/>
98-
))}
99-
</>
100-
)}
101-
</div>
102-
<div className="mt-8 flex justify-end">
103-
<button
104-
className="w-full rounded-full border-4 border-white bg-apricot px-10 py-2 text-white disabled:opacity-50 md:w-auto md:px-12"
105-
type="submit"
106-
disabled={teamMutation.isPending || teamMutation.isSuccess}
107-
>
108-
{teamMutation.isPending ? "Leaving Team..." : "Leave Team"}
109-
</button>
110-
</div>
111-
</form>
43+
{data && (
44+
<>
45+
<form className={FORM_STYLES}>
46+
<label>Team ID</label>
47+
<input
48+
className={INPUT_STYLES}
49+
type="text"
50+
placeholder={data.id ?? "Team ID"}
51+
disabled
52+
/>
53+
<label>Team Name</label>
54+
<input
55+
className={INPUT_STYLES}
56+
type="text"
57+
placeholder={data.name ?? "Team Name"}
58+
disabled
59+
/>
60+
<label>Team Members</label>
61+
<div className="flex flex-col">
62+
{isFetching ? (
63+
<h1 className={INPUT_STYLES}>Loading...</h1>
64+
) : (
65+
<>
66+
{Array.isArray(teamData?.members) &&
67+
teamData?.members.map(
68+
(member: Partial<Schema["User"]["type"]>) => (
69+
<input
70+
key={member.id}
71+
className={INPUT_STYLES}
72+
type="text"
73+
value={`${member.firstName} ${member.lastName}`}
74+
disabled
75+
/>
76+
),
77+
)}
78+
</>
79+
)}
80+
</div>
81+
</form>
82+
<div className="mb-10 mt-3 flex justify-end md:mx-10">
83+
<button
84+
className={`${BUTTON_STYLES} w-full md:w-auto`}
85+
onClick={handleLeaveTeamClick}
86+
>
87+
Leave Team
88+
</button>
89+
</div>
90+
</>
91+
)}
11292
</>
11393
);
11494
}

src/components/UserProfile/TeamProfile.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
99

1010
const BUTTON_STYLES =
1111
" rounded-full border-4 border-white bg-grapefruit px-10 md:px-12 py-2 my-2 text-white";
12-
1312
const TEAM_INSTRUCTION_STYLES =
1413
"bg-pink bg-white/30 mx-10 my-10 rounded-3xl border-4 border-white bg-white px-10 py-20 md:px-20 md:py-16";
15-
1614
const TeamProfile = () => {
1715
const queryClient = useQueryClient();
18-
1916
const userTeamId = useUser().currentUser.teamId as string;
20-
2117
const { data, isFetching } = useQuery({
2218
initialData: {} as Schema["Team"]["type"],
2319
initialDataUpdatedAt: 0,
@@ -26,14 +22,11 @@ const TeamProfile = () => {
2622
const teamResponse = await client.models.Team.get({
2723
id: userTeamId,
2824
});
29-
3025
if (teamResponse.errors) throw new Error(teamResponse.errors[0].message);
31-
3226
return teamResponse.data;
3327
},
3428
enabled: !!userTeamId,
3529
});
36-
3730
const teamMutation = useMutation({
3831
mutationFn: async () => {
3932
try {
@@ -49,7 +42,6 @@ const TeamProfile = () => {
4942
});
5043
},
5144
});
52-
5345
return (
5446
<>
5547
{isFetching || !userTeamId ? (
@@ -113,4 +105,5 @@ const TeamProfile = () => {
113105
)}
114106
</>
115107
);
116-
}
108+
};
109+
export default TeamProfile;

src/components/UserProfile/UserForm.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
import { useState } from "react";
44
import { useFormStatus } from "react-dom";
5-
import { type Schema } from "@/amplify/data/resource";
6-
import { type UserFormProp } from "@/components/UserProfile/UserProfile";
5+
import { useUser } from "../contexts/UserContext";
76

7+
interface UserFormProp {
8+
setIsEditing: React.Dispatch<React.SetStateAction<boolean>>;
9+
setEnableCancelSave: React.Dispatch<React.SetStateAction<boolean>>;
10+
enableCancelSave: boolean;
11+
isEditing: boolean;
12+
userMutation: any;
13+
}
814
export default function UserForm({
915
userMutation,
1016
setIsEditing,
@@ -58,7 +64,6 @@ export default function UserForm({
5864
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChange(e)}
5965
name="lastName"
6066
value={formState.lastName ?? ""}
61-
name={"lastName"}
6267
disabled={!isEditing}
6368
/>
6469
</div>
@@ -128,7 +133,7 @@ export default function UserForm({
128133
<input
129134
className={`${"md:text-md my-2 rounded-full border-4 border-white bg-white py-2 ps-3 text-sm"} ${"text-ehhh-grey"}`}
130135
type="text"
131-
value={formState.checkedIn ? "Yes" : "No"}
136+
value={formState.completedRegistration ? "Yes" : "No"}
132137
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChange(e)}
133138
readOnly
134139
/>

src/components/UserProfile/UserProfile.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
import Image from "next/image";
44
import { useState } from "react";
5-
import { type Schema } from "@/amplify/data/resource";
65
import { client } from "@/app/QueryProvider";
6+
import type { IUser } from "@/components/contexts/UserContext";
77
import { useUser } from "@/components/contexts/UserContext";
88
import KevinLoadingRing from "@/components/KevinLoadingRing";
99
import UserForm from "@/components/UserProfile/UserForm";
10-
import { useMutation, useQuery } from "@tanstack/react-query";
10+
import { useMutation } from "@tanstack/react-query";
1111

1212
export default function UserProfile() {
13-
const { currentUser: data, isFetching: userContextIsFetching } = useUser();
13+
const { isFetching: userContextIsFetching } = useUser();
1414

1515
const userMutation = useMutation({
1616
mutationKey: ["User"],
17-
mutationFn: async (input: typeof data) => {
17+
mutationFn: async (input: IUser) => {
1818
try {
1919
await client.models.User.update(input);
2020
} catch (error) {
21-
throw new Error("Failed to update user");
21+
throw new Error("Failed to update user " + error);
2222
}
2323
},
2424
});
@@ -65,10 +65,10 @@ export default function UserProfile() {
6565
/>{" "}
6666
</div>
6767
<div className="w-full md:px-16 md:py-10">
68-
<div className="mb-3 flex justify-between uppercase text-apricot md:mx-10">
68+
<div className="text-apricot mb-3 flex justify-between uppercase md:mx-10">
6969
<h1 className="mt-3 text-lg font-bold md:text-2xl">My Details</h1>
7070
<button
71-
className=" my-2 rounded-full border-4 border-white bg-apricot px-10 py-2 text-white md:px-12"
71+
className=" bg-apricot my-2 rounded-full border-4 border-white px-10 py-2 text-white md:px-12"
7272
onClick={handleEditClick}
7373
>
7474
Edit

0 commit comments

Comments
 (0)