Skip to content

Commit

Permalink
feat: normalize profile mentions (#604)
Browse files Browse the repository at this point in the history
* feat: normalize profile mentions

* chore: implement suggestions

* fix: qr reader

* fix: remove includes
  • Loading branch information
MarioRodrigues10 authored Jan 16, 2024
1 parent f8f1da6 commit ee42771
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 21 deletions.
4 changes: 2 additions & 2 deletions layout/Attendee/Wheel/Wheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function WheelPage() {
.then((response) => updateLatestWins(response.data))
.catch((_) => updateError(true));
};

useEffect(requestAllInfo, []);

const canSpin = () => {
Expand Down Expand Up @@ -176,7 +175,8 @@ function WheelPage() {
const latestWinsComponents = latestWins.map((entry, id) => (
<ListItem3Cols
key={id}
user={entry.attendee_name}
user_name={entry.attendee_name}
user_nickname={entry.attendee_nickname}
prize={entry.prize}
when={displayTimeSince(entry.date)}
isLast={id == latestWins.length - 1}
Expand Down
9 changes: 7 additions & 2 deletions layout/Attendee/Wheel/components/ListItem3Cols/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Link from "next/link";

export default function ListItem3Cols({
user,
user_name,
user_nickname,
prize,
when,
isLast = false,
Expand All @@ -13,7 +16,9 @@ export default function ListItem3Cols({
return (
<div className={`mb-5 w-full pb-3 ${border} grid grid-cols-5 items-center`}>
<div className="text-left">
<p className="font-ibold">{user}</p>
<Link href={`/attendees/${user_nickname}`}>
<p className="font-ibold">{user_name}</p>
</Link>
</div>
<div className="select-none justify-self-end">
<img src={prize.avatar} className="w-10" />
Expand Down
28 changes: 20 additions & 8 deletions layout/Attendees/Attendees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BadgeFilter from "@components/BadgeFilter";

import Layout from "@components/Layout";
import Heading from "@components/Heading";
import { getAttendee, isAttendeeRegistered } from "@lib/api";
import { getAttendeeByID, getAttendeeByUsername } from "@lib/api";

function Profile() {
const [attendee, updateAttendee] = useState(null);
Expand All @@ -17,14 +17,26 @@ function Profile() {
const [filter, updateFilter] = useState(null);

useEffect(() => {
getAttendee(uuid)
.then((response) => {
const fetchData = async () => {
try {
const response = await getAttendeeByID(uuid);
updateAttendee(response.data);
})
.catch((error) => {
router.replace("/404");
});
}, []);
} catch (error) {
if (error.response && error.response.status === 400) {
try {
const response = await getAttendeeByUsername(uuid);
updateAttendee(response.data);
} catch (usernameError) {
router.replace("/404");
}
} else {
router.replace("/404");
}
}
};

fetchData();
}, [uuid, router, updateAttendee]);

if (!attendee) return null;
return (
Expand Down
2 changes: 0 additions & 2 deletions layout/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const BadgeSlug: React.FC = () => {
.catch((_) => router.replace("/404"));
}, [slug]);

console.log(badge);

return (
<Layout
title={`${badge?.name} Badge`}
Expand Down
4 changes: 2 additions & 2 deletions layout/Staff/Identifier/Identifier.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef, useEffect } from "react";

import { getAttendee } from "@lib/api";
import { getAttendeeByID } from "@lib/api";

import { withAuth } from "@context/Auth";

Expand Down Expand Up @@ -36,7 +36,7 @@ function Identifier() {
}, [feedback]);

const handleUUID = (uuid) => {
getAttendee(uuid)
getAttendeeByID(uuid)
.then((response) => {
setText(`${response.data.name} | ${response.data.email}`);
setFeedback(FEEDBACK.SUCCESS);
Expand Down
3 changes: 2 additions & 1 deletion layout/shared/Leaderboard/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Link from "next/link";

export default function Table({ list, user, maxUsersToShow }) {
const toShow = list.slice(0, Math.min(maxUsersToShow, list.length));

const rows = toShow.map((entry, id) => (
<div key={id} className=" flex h-auto border-t-2 border-t-slate-300 p-4">
<div
Expand All @@ -16,7 +17,7 @@ export default function Table({ list, user, maxUsersToShow }) {
entry.id == user ? "text-quinary" : ""
}`}
>
<Link href={`/attendees/${entry.id}`}>{entry.name}</Link>
<Link href={`/attendees/${entry.nickname}`}>{entry.name}</Link>
</div>
<div
className={`w-1/3 text-right font-iregular ${
Expand Down
25 changes: 21 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,22 @@ export async function sendResetEmail({ email }) {
return response.data;
}

export async function getAttendee(id) {
const response = await API.get(`/api/attendees/${id}`);
export async function getAttendeeByID(id) {
const response = await API.get(`/api/attendees/${id}`, {
params: {
id,
},
});

return response.data;
}

export async function getAttendeeByUsername(username) {
const response = await API.get(`/api/attendees/${username}`, {
params: {
username,
},
});

return response.data;
}
Expand Down Expand Up @@ -203,8 +217,11 @@ export async function getCurrentUser() {
const { data: attendee } = await API.get("/api/attendee");
const {
data: { data: extras },
} = await API.get(`/api/attendees/${attendee.id}`);

} = await API.get(`/api/attendees/${attendee.id}`, {
params: {
id: attendee.id,
},
});
return { ...attendee, ...extras, type };
case USER.ROLES.STAFF:
return response.data;
Expand Down

0 comments on commit ee42771

Please sign in to comment.