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

leaderboard update #509

Merged
merged 7 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
94 changes: 52 additions & 42 deletions apps/battlepass-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { cors } from 'hono/cors';
import { createClient } from '@supabase/supabase-js';

export type Bindings = {
HIBISCUS_SUPABASE_SERVICE_KEY: string;
NEXT_PUBLIC_HIBISCUS_SUPABASE_API_URL: string;
HIBISCUS_SUPABASE_SERVICE_KEY: string;
NEXT_PUBLIC_HIBISCUS_SUPABASE_API_URL: string;
};

const HTTP_BAD_REQUEST = 400;
Expand All @@ -15,59 +15,69 @@ const app = new Hono<{ Bindings: Bindings }>();
app.use('/api/*', cors());

app.get('/api/leaderboard', async (c) => {
try {
const supabase = createClient(
c.env.NEXT_PUBLIC_HIBISCUS_SUPABASE_API_URL,
c.env.HIBISCUS_SUPABASE_SERVICE_KEY
);
try {
const supabase = createClient(
c.env.NEXT_PUBLIC_HIBISCUS_SUPABASE_API_URL,
c.env.HIBISCUS_SUPABASE_SERVICE_KEY
);

const pageNumber = parseInt(c.req.query("pageNumber") ?? "");
const pageSize = parseInt(c.req.query("pageSize") ?? "");
const pageNumber = parseInt(c.req.query('pageNumber') ?? '');
const pageSize = parseInt(c.req.query('pageSize') ?? '');

if (isNaN(pageNumber) || isNaN(pageSize) || pageNumber < 1 || pageSize < 1) {
return c.json({
error: 'INVALID_QUERY_PARAMS',
message: 'Please provide valid pageNumber and pageSize.',
}, HTTP_BAD_REQUEST);
}
if (
isNaN(pageNumber) ||
isNaN(pageSize) ||
pageNumber < 1 ||
pageSize < 1
) {
return c.json(
{
error: 'INVALID_QUERY_PARAMS',
message: 'Please provide valid pageNumber and pageSize.',
},
HTTP_BAD_REQUEST
);
}

const { data, error } = await supabase
.from('leaderboard')
.select(`
const { data, error } = await supabase
.from('leaderboard')
.select(
`
bonus_points,
event_points,
total_points,
user_profiles(
first_name,
last_name
)
`)
.order('total_points', {ascending: false})
.range((pageNumber - 1) * pageSize, pageNumber * pageSize - 1)
`
)
.order('total_points', { ascending: false })
.range((pageNumber - 1) * pageSize, pageNumber * pageSize - 1);

if (error) {
return c.json({ error: error.message }, INTERNAL_SERVER_ERROR);
}
if (error) {
return c.json({ error: error.message }, INTERNAL_SERVER_ERROR);
}

return c.json({
data: {
pageNumber: pageNumber,
pageCount: pageSize,
leaderboard: data
}
});
} catch (e) {
if(e instanceof Error){
console.error("Error:", e.message); // Extract and log the error message.
}
return c.json(
{
error: 'UNKNOWN_ERROR',
message: 'An unknown error occurred.',
},
INTERNAL_SERVER_ERROR
);
return c.json({
data: {
pageNumber: pageNumber,
pageCount: pageSize,
leaderboard: data,
},
});
} catch (e) {
if (e instanceof Error) {
console.error('Error:', e.message); // Extract and log the error message.
}
return c.json(
{
error: 'UNKNOWN_ERROR',
message: 'An unknown error occurred.',
},
INTERNAL_SERVER_ERROR
);
}
});

export default app;
14 changes: 13 additions & 1 deletion apps/dashboard/common/apis/battlepass/battlepass.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HibiscusSupabaseClient } from '@hibiscus/hibiscus-supabase-client';
import { SupabaseClient } from '@supabase/supabase-js';
import { BonusPointsStatus } from './types';
import { container } from 'tsyringe';
import { BattlePassRepository } from 'apps/dashboard/repository/battlepass.repository';
import { BattlePassRepository } from '../../../repository/battlepass.repository';
import axios from 'axios';

const getNumberStatusBonusPoint = (status: BonusPointsStatus) => {
Expand Down Expand Up @@ -64,6 +64,7 @@ export interface BattlepassAPIInterface {
bonusPointsId: string,
status: BonusPointsStatus
) => Promise<void>;
setBonusPointPending: (userId: string, bonusPointId: string) => Promise<void>;
}

export class BattlepassAPI implements BattlepassAPIInterface {
Expand Down Expand Up @@ -136,6 +137,17 @@ export class BattlepassAPI implements BattlepassAPIInterface {
}
}

async setBonusPointPending(userId: string, bonusPointId: string) {
try {
await axios.post('/api/battlepass/bonus-points', {
userId,
bonusPointId,
});
} catch (e) {
throw new Error('Failed to set bonus points');
}
}

async getBonusPointEventsUserStatus(userId: string): Promise<{
data: {
id: string;
Expand Down
84 changes: 60 additions & 24 deletions apps/dashboard/components/battlepass/battlepass-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { H3, Text } from '@hibiscus/ui';
import { GlobalStyles } from '@hibiscus/styles';
import {
GlobalStyle,
BodyTextSmall,
BodyText,
Heading,
} from '@hacksc/sctw-ui-kit';
import { useBattlepassAPI } from '../../hooks/use-battlepass-api/use-battlepass-api';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -56,38 +63,23 @@ function BattlepassPage() {
return (
<Wrapper>
<BattlepassWelcomeHeader />
<Image
width="100"
height="100"
src={'/hackform-illustrations/stamp-earth.svg'}
alt="Illustration"
style={{
position: 'absolute',
left: '420px',
top: '10px',
}}
/>
<WidgetContainer>
<WidgetHeader>Your Points</WidgetHeader>
{bpProg !== null && (
<BattlepassPointsBar
rangeMinPoint={bpProg.level}
rangeMaxPoint={bpProg.nextLevel}
currentPoint={userPoints}
minLabel={
<Text>
Current points: <GlowSpan>{userPoints}</GlowSpan>
</Text>
}
minLabel={<YellowPoints>{userPoints} PTS</YellowPoints>}
maxLabel={
BATTLEPASS_LEVEL_POINTS[bpProg.level] <
BATTLEPASS_LEVEL_POINTS[3] ? (
<Text>
Next level points:{' '}
<GlowSpan color={Colors2023.BLUE.STANDARD}>
{bpProg.nextLevel}
</GlowSpan>
</Text>
<PreNextLevelText>
Next level @{' '}
<NextLevelTextSpan color={Colors2023.BLUE.STANDARD}>
{bpProg.nextLevel} PTS
</NextLevelTextSpan>
</PreNextLevelText>
) : null
}
/>
Expand Down Expand Up @@ -117,10 +109,44 @@ function BattlepassPage() {

export default BattlepassPage;

const PreNextLevelText = styled(BodyTextSmall)`
color: #939393;
font-size: 15px;
font-style: normal;
font-weight: 400;
line-height: normal;
`;
const NextLevelTextSpan = styled.span`
color: var(--Redward, #ff514f);
text-align: center;
/* smaller red glow */
text-shadow: 0px 0px 10px rgba(255, 94, 92, 0.5);
font-style: normal;
font-weight: 700;
line-height: normal;
letter-spacing: 0;
text-transform: uppercase;
`;

const YellowPoints = styled(BodyTextSmall)`
color: var(--Arthurs-Sweater, #ecb400);
text-align: center;
/* smaller yellow glow */
text-shadow: 0px 0px 10px #ffd13c;
font-size: 15px;
font-style: normal;
font-weight: 700;
line-height: normal;
letter-spacing: 0;
text-transform: uppercase;
`;

const Wrapper = styled.div`
display: flex;
flex-direction: column;
gap: 2rem;
background-color: white;
padding-bottom: 50px;
`;

const WidgetContainer = styled.div`
Expand All @@ -143,9 +169,19 @@ const RightColumnSecondSection = styled.div`

const SecondSection = styled.div`
display: flex;

gap: 30px;
@media (max-width: 1024px) {
flex-direction: column;
}
`;

const WidgetHeader = styled(H3)`
font-size: 120%;
const WidgetHeader = styled.p`
font-family: 'filson-pro', sans-serif;
color: var(--Redward, #ff514f);
font-size: 20px;
font-style: normal;
font-weight: 700;
line-height: normal;
letter-spacing: -1.25px;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const BarFront = styled.div<{ progress: number }>`
`;

const BottomDiv = styled.div`
margin-top: 8px;
display: flex;
justify-content: space-between;
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Colors2023 } from '@hibiscus/styles';
import { H1, Text } from '@hibiscus/ui';

import useHibiscusUser from '../../hooks/use-hibiscus-user/use-hibiscus-user';

export const BattlepassWelcomeHeader = () => {
Expand All @@ -16,14 +17,15 @@ export const BattlepassWelcomeHeader = () => {
<div>
<H1
style={{
color: Colors2023.BLUE.STANDARD,
color: 'black',
fontSize: '30px',
fontFamily: "'filson-pro', sans-serif",
}}
>
Welcome, {user.firstName}
Your Leaderboard
</H1>
<Text style={{ color: '#989898' }}>
What would you like to do today?
Check your ranking on the leaderboard and win prizes!
</Text>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { H3, H4, Text } from '@hibiscus/ui';
import { Button } from '@hibiscus/ui-kit-2023';
// import { Button } from '@hibiscus/ui-kit-2023';
import { Button } from '@hacksc/sctw-ui-kit';
import React from 'react';
import styled from 'styled-components';
import { BonusPointsStatus } from '../../../common/apis/battlepass/types';
Expand All @@ -13,13 +14,13 @@ interface Props {
function BonusPointsItem({ data, handleClick }: Props) {
return (
<Container>
<div>
<Text style={{ color: 'gray' }}>{data.points} pts</Text>
<TextDiv>
<Text style={{ color: 'white' }}>{data.points} pts</Text>
<H4>{data.title}</H4>
</div>
</TextDiv>
<div>
<Button
color="black"
color="yellow"
disabled={data.status !== BonusPointsStatus.VERIFY}
onClick={handleClick}
>
Expand All @@ -32,9 +33,19 @@ function BonusPointsItem({ data, handleClick }: Props) {

export default BonusPointsItem;

const TextDiv = styled.div`
@media (max-width: 768px) {
width: 100%;
}
`;

const Container = styled.div`
display: flex;
justify-content: space-between;
@media (max-width: 768px) {
flex-direction: column;
align-items: center;
}
padding: 10px;
gap: 10px;
`;
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { H3, Modal, Text, Link } from '@hibiscus/ui';
import { Button } from '@hibiscus/ui-kit-2023';
import { Button } from '@hacksc/sctw-ui-kit';
import React, { useState } from 'react';
import styled from 'styled-components';
import { BonusPointsStatus } from '../../../common/apis/battlepass/types';
import { useBattlepassAPI } from '../../../hooks/use-battlepass-api/use-battlepass-api';
import useHibiscusUser from '../../../hooks/use-hibiscus-user/use-hibiscus-user';
import { GrayBox } from '../../gray-box/gray-box';
Expand Down Expand Up @@ -38,7 +37,7 @@ function BattlepassBonusPointsList({ items }: Props) {
<Text>{chosenBP?.description}</Text>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Link href={chosenBP?.link ?? ''} passHref>
<Button color="black">SUBMIT FORM</Button>
<Button color="yellow">SUBMIT FORM</Button>
</Link>
</div>
</GrayBox>
Expand All @@ -50,11 +49,7 @@ function BattlepassBonusPointsList({ items }: Props) {
handleClick={async () => {
setChosenBP(item);
setOpen(true);
await battlepassApi.updateUserBonusPointStatus(
user.id,
item.id,
BonusPointsStatus.PENDING
);
await battlepassApi.setBonusPointPending(user.id, item.id);
}}
/>
))}
Expand Down
Loading
Loading