Skip to content

Commit 752516d

Browse files
committed
team members loaded and mobile fix
1 parent daff537 commit 752516d

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

amplify/data/resource.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const schema = a
2525
allow.ownerDefinedIn("profileOwner").to(["read", "create"]),
2626
allow.groups(["Admin"]).to(["read", "update", "create"]),
2727
]),
28-
email: a.string(),
28+
email: a
29+
.string()
30+
.authorization((allow) => [
31+
allow.ownerDefinedIn("profileOwner").to(["read", "create"]),
32+
allow.groups(["Admin"]).to(["read", "create"]),
33+
]),
2934
institution: a.string(),
3035
completedRegistration: a.boolean(),
3136
allergies: a.string(),

src/components/UserProfile/TeamForm.tsx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
"use client";
2+
3+
import { generateClient } from "aws-amplify/api";
4+
15
import { type Schema } from "@/amplify/data/resource";
6+
import { useQuery } from "@tanstack/react-query";
27

38
const INPUT_STYLES =
49
"rounded-full border-4 placeholder-black border-white bg-[#FFFFFF] bg-white/30 ps-3 py-2 my-2 text-sm md:text-md backdrop-opacity-30";
@@ -17,7 +22,23 @@ export default function TeamForm({ data, teamMutation }: TeamFormProp) {
1722
teamMutation.mutate(data);
1823
};
1924

25+
const client = generateClient<Schema>();
26+
2027
// eslint-disable-next-line @typescript-eslint/no-unused-vars
28+
const { data: teamData, isFetching } = useQuery({
29+
initialData: null,
30+
initialDataUpdatedAt: 0,
31+
queryKey: ["TeamWithMembers"],
32+
queryFn: async () => {
33+
const { data: teamWithMembers } = await client.models.Team.get(
34+
{ id: data.id },
35+
{ selectionSet: ["id", "members.*"] },
36+
);
37+
38+
return teamWithMembers;
39+
},
40+
enabled: !!data,
41+
});
2142

2243
return (
2344
<>
@@ -40,16 +61,24 @@ export default function TeamForm({ data, teamMutation }: TeamFormProp) {
4061
/>
4162
<label>Team Members</label>
4263
<div className="flex flex-col">
43-
{Array.isArray(data.members) &&
44-
data.members.map((member: Schema["User"]["type"]) => (
45-
<input
46-
key={member.id}
47-
className={INPUT_STYLES}
48-
type="text"
49-
value={`${member.firstName} ${member.lastName}`}
50-
disabled
51-
/>
52-
))}
64+
{isFetching ? (
65+
<h1 className={INPUT_STYLES}>Loading...</h1>
66+
) : (
67+
<>
68+
{Array.isArray(teamData?.members) &&
69+
teamData?.members.map(
70+
(member: Partial<Schema["User"]["type"]>) => (
71+
<input
72+
key={member.id}
73+
className={INPUT_STYLES}
74+
type="text"
75+
value={`${member.firstName} ${member.lastName}`}
76+
disabled
77+
/>
78+
),
79+
)}
80+
</>
81+
)}
5382
</div>
5483
</form>
5584
<div className="mb-10 mt-3 flex justify-end md:mx-10">

src/components/UserProfile/TeamProfile.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,13 @@ const TEAM_INSTRUCTION_STYLES =
1616
const TeamProfile = () => {
1717
const queryClient = useQueryClient();
1818

19-
const userId = useUser().currentUser.username as string;
19+
const userTeamId = useUser().currentUser.teamId as string;
2020

2121
const { data, isFetching } = useQuery({
2222
initialData: {} as Schema["Team"]["type"],
2323
initialDataUpdatedAt: 0,
24-
queryKey: ["Team", userId],
24+
queryKey: ["Team", userTeamId],
2525
queryFn: async () => {
26-
const userResponse = await client.models.User.get({
27-
id: userId,
28-
});
29-
30-
if (userResponse.errors) throw new Error(userResponse.errors[0].message);
31-
32-
const userTeamId = userResponse.data?.teamId as string;
33-
34-
if (!userTeamId) {
35-
return {} as Schema["Team"]["type"];
36-
}
37-
3826
const teamResponse = await client.models.Team.get({
3927
id: userTeamId,
4028
});
@@ -43,27 +31,28 @@ const TeamProfile = () => {
4331

4432
return teamResponse.data;
4533
},
34+
enabled: !!userTeamId,
4635
});
4736

4837
const teamMutation = useMutation({
4938
mutationFn: async () => {
5039
try {
51-
await client.models.User.update({ id: userId, teamId: null });
40+
await client.models.User.update({ id: userTeamId, teamId: null });
5241
} catch (error) {
5342
console.error("Error updating ids", error);
5443
throw error;
5544
}
5645
},
5746
onSuccess: () => {
5847
queryClient.invalidateQueries({
59-
queryKey: ["Team", userId],
48+
queryKey: ["Team", userTeamId],
6049
});
6150
},
6251
});
6352

6453
return (
6554
<>
66-
{isFetching ? (
55+
{isFetching || !userTeamId ? (
6756
<div className="flex h-screen w-full items-center justify-center bg-fuzzy-peach">
6857
<LoadingRing />
6958
</div>

src/components/admin/Judging/JudgingTimeline.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export default function JudgingTimeline({
4141
colorField: "color",
4242
}}
4343
day={{
44-
startHour: 15, // will have to be edited when we know what times to capture
45-
endHour: 18,
46-
step: 15,
44+
startHour: 12, // will have to be edited when we know what times to capture
45+
endHour: 17,
46+
step: 10,
4747
}}
4848
deletable={false}
4949
viewerExtraComponent={(fields, event) => {

src/components/contexts/UserContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function UserContextProvider({ children }: Props) {
9696
populated: true,
9797
completedProfile: response.data?.completedRegistration ?? false,
9898
email: response.data?.email ?? "",
99+
teamId: response.data?.teamId ?? "",
99100
firstName: response.data?.firstName ?? "",
100101
lastName: response.data?.lastName ?? "",
101102
JUDGE_roomId: response.data?.JUDGE_roomId,

0 commit comments

Comments
 (0)