Skip to content

Commit

Permalink
Merge pull request #116 from ubc-biztech/fix-merge
Browse files Browse the repository at this point in the history
Fix merge
  • Loading branch information
voctory authored Jan 25, 2025
2 parents 13d7109 + 17689bc commit fe058f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 60 deletions.
30 changes: 10 additions & 20 deletions src/components/companion/connections/connections-list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { SectionCard } from '@/components/ui/section-card';
import { CompanionConnectionRow } from './connection-row';
import React from "react";
import { SectionCard } from "@/components/ui/section-card";
import { CompanionConnectionRow } from "./connection-row";

export interface Connection {
userID: string;
Expand All @@ -12,7 +12,6 @@ export interface Connection {
year?: string;
title?: string;
company?: string;
linkedinURL?: string;
profilePic?: string;
"eventID;year": string;
}
Expand All @@ -22,35 +21,26 @@ interface ConnectionsListProps {
totalCount?: number;
}

export const ConnectionsList: React.FC<ConnectionsListProps> = ({
connections,
totalCount
}) => {
export const ConnectionsList: React.FC<ConnectionsListProps> = ({ connections, totalCount }) => {
return (
<SectionCard title="Connections" viewAllLink="/companion/connections">
<div className="space-y-4">
<SectionCard title='Connections' viewAllLink='/companion/connections'>
<div className='space-y-4'>
{totalCount && totalCount > 0 ? (
<>
{connections.map((connection, index) => (
<CompanionConnectionRow key={index} connection={connection} />
))}
{totalCount && totalCount > connections.length && (
<p className="text-center text-[#808080] text-xs mt-2 font-redhat">
+ {totalCount - connections.length} MORE
</p>
<p className='text-center text-[#808080] text-xs mt-2 font-redhat'>+ {totalCount - connections.length} MORE</p>
)}
</>
) : (
<>
<p className="font-redhat font-thin text-[14px] flex justify-center text-center">
NO CONNECTIONS YET
</p>
<p className="font-redhat font-thin text-[14px] flex justify-center text-center">
TAP YOUR FIRST NFC TO START
</p>
<p className='font-redhat font-thin text-[14px] flex justify-center text-center'>NO CONNECTIONS YET</p>
<p className='font-redhat font-thin text-[14px] flex justify-center text-center'>TAP YOUR FIRST NFC TO START</p>
</>
)}
</div>
</SectionCard>
);
};
};
41 changes: 20 additions & 21 deletions src/pages/companion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { Event } from "@/constants/companion-events";
import Loading from "@/components/Loading";
import { COMPANION_EMAIL_KEY, COMPANION_PROFILE_ID_KEY } from "@/constants/companion";
import { Badge } from "./badges";
import { Loader2 } from "lucide-react";

interface Registration {
id: string;
Expand Down Expand Up @@ -104,7 +105,7 @@ const Companion = () => {
repeatDelay: 0.5
},
whileHover: {
x: '0%' // Stops the animation on hover
x: "0%" // Stops the animation on hover
}
};

Expand All @@ -131,15 +132,19 @@ const Companion = () => {
logo: "w-1/2 sm:w-3/5 mb-5 relative",
title: "text-2xl font-bold mb-2 text-white font-satoshi",
description: "text-center mb-4 text-white p1 font-satoshi",
input: "mb-4 w-64 font-satoshi text-white backdrop-blur-sm bg-white/5 border-white/10 transition-all duration-300 focus:bg-white/10 focus:border-white/20",
button: "mb-4 font-satoshi relative overflow-hidden bg-[#1E88E5] hover:bg-[#1976D2] text-white px-8 py-2 rounded-full transition-all duration-300 shadow-[0_0_15px_rgba(30,136,229,0.3)] hover:shadow-[0_0_20px_rgba(30,136,229,0.5)]",
buttonShine: "absolute inset-0 transform bg-gradient-to-r from-[#1E88E5] hover:from-[#1976D2] via-white/20 hover:to-[#1976D2] to-[#1E88E5]",
input:
"mb-4 w-64 font-satoshi text-white backdrop-blur-sm bg-white/5 border-white/10 transition-all duration-300 focus:bg-white/10 focus:border-white/20",
button:
"mb-4 font-satoshi relative overflow-hidden bg-[#1E88E5] hover:bg-[#1976D2] text-white px-8 py-2 rounded-full transition-all duration-300 shadow-[0_0_15px_rgba(30,136,229,0.3)] hover:shadow-[0_0_20px_rgba(30,136,229,0.5)]",
buttonShine:
"absolute inset-0 transform bg-gradient-to-r from-[#1E88E5] hover:from-[#1976D2] via-white/20 hover:to-[#1976D2] to-[#1E88E5]",
error: "text-red-500 text-center w-4/5 font-satoshi"
};

const fetchUserData = async () => {
const reg = registrations.find((entry) => entry.id.toLowerCase() === email.toLowerCase());
if (reg) {
setIsLoading(true);
setError("");
setUserRegistration(reg);
localStorage.setItem(COMPANION_EMAIL_KEY, reg.id);
Expand All @@ -155,20 +160,25 @@ const Companion = () => {
if (profileResponse.profileID) {
localStorage.setItem(COMPANION_PROFILE_ID_KEY, profileResponse.profileID);
// After setting profile ID, fetch connections and badges
if (decodedRedirect !== "") {
router.push(decodedRedirect);
return;
}

if (!reg.isPartner) await Promise.all([fetchConnections(), fetchBadges()]);
else await fetchConnections();
}
} catch (err) {
console.error("Error fetching profile ID:", err);
}

if (decodedRedirect !== "") {
router.push(decodedRedirect);
}
} else {
setError("This email does not match an existing entry in our records.");
setIsLoading(false);
}

setIsLoading(false);
};

const fetchRegistrations = async () => {
Expand Down Expand Up @@ -245,30 +255,19 @@ const Companion = () => {

useEffect(() => {
const { query } = router;
const redirectParam = query[""] ? decodeURIComponent(query[""] as string) : "";
const redirectParam = query["redirect"] ? decodeURIComponent(query["redirect"] as string) : "";
setDecodedRedirect(redirectParam);

// I personally think this is hacky but equally viable
// if (typeof window !== "undefined") {
// const search = window.location.search;

// if (search.startsWith("?=")) {
// setDecodedRedirect(decodeURIComponent(search.slice(2)));
// }
// }
}, [router]);
}, [router.isReady]);

useEffect(() => {
const initializeData = async () => {
setIsLoading(true);
const savedEmail = localStorage.getItem(COMPANION_EMAIL_KEY);
if (savedEmail) {
setEmail(savedEmail);
}
setIsLoading(false);

await Promise.all([fetchRegistrations(), fetchEvent()]);

setIsLoading(false);
};

initializeData();
Expand All @@ -278,7 +277,7 @@ const Companion = () => {
if (email && registrations.length > 0) {
fetchUserData();
}
}, [email, registrations]);
}, [email, registrations, router.isReady]);

if (isLoading) return <Loading />;

Expand Down
3 changes: 0 additions & 3 deletions src/pages/companion/login/redirect/index.tsx

This file was deleted.

23 changes: 7 additions & 16 deletions src/pages/companion/scan/[qrId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { fetchBackend } from "@/lib/db";
import { Loader2, QrCodeIcon } from "lucide-react";
import { QrCodeIcon } from "lucide-react";
import PageError from "@/components/companion/PageError";
import Events from "@/constants/companion-events";
import { BOOTH_EVENT, COMPANION_EMAIL_KEY, COMPANION_PROFILE_ID_KEY, CONNECTION_EVENT, WORKSHOP_EVENT } from "@/constants/companion";
import Loading from "@/components/Loading";

interface Qr {
data: Record<string, any>;
Expand Down Expand Up @@ -41,7 +42,6 @@ const Index = () => {
authenticatedCall: false
});

console.log(response);
setQrData(response);
setQrLoading(false);
} catch (err) {
Expand All @@ -64,16 +64,12 @@ const Index = () => {
Object.assign(body, { eventType: CONNECTION_EVENT });
redirect = `/companion/profile/${eventParam}`;
break;
case "NFC_BOOTH":
case "NFC_COMPANY":
Object.assign(body, { eventType: BOOTH_EVENT });
// TODO: company pages
// redirect = `/companion/booth/${eventParam}`;
redirect = `/companion/`;
redirect = `/companion/profile/company/${eventParam}`;
break;
case "NFC_WORKSHOP":
Object.assign(body, { eventType: WORKSHOP_EVENT });
// TODO: workshop pages
// redirect = `/companion/workshop/${eventParam}`;
redirect = `/companion/`;
break;
default:
Expand Down Expand Up @@ -108,14 +104,14 @@ const Index = () => {
const userID = localStorage.getItem(COMPANION_EMAIL_KEY);

if (!userID) {
router.push(`/companion/login/redirect?=/companion/scan/${qrId}`);
router.push(`/companion?redirect=/companion/scan/${qrId}`);
return;
}

postInteraction(userID || "", type, id); // TODO integrate profiles
}, [qrData]);

if (!loadingQr && (!qrData || !["NFC_ATTENDEE", "NFC_BOOTH", "NFC_WORKSHOP"].includes(qrData.type))) {
if (!loadingQr && (!qrData || !["NFC_ATTENDEE", "NFC_BOOTH", "NFC_WORKSHOP", "NFC_COMPANY"].includes(qrData.type))) {
return (
<PageError
icon={<QrCodeIcon size={64} color='#F87171' />}
Expand All @@ -130,12 +126,7 @@ const Index = () => {
return <div className='w-screen h-screen flex items-center justify-center'>{pageError}</div>;
}

// loading spinner
return (
<div className='w-screen h-screen flex items-center justify-center'>
<Loader2 className='animate-spin' size={50} />
</div>
);
return <Loading />;
};

export default Index;

0 comments on commit fe058f4

Please sign in to comment.