Skip to content

Commit

Permalink
Implement award points page
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 committed Jan 16, 2024
1 parent 6dd185c commit 1b5f445
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/lib/api/EventAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { config } from '@/lib';
import { FillInLater, UUID } from '@/lib/types';
import { AttendEventRequest, Event } from '@/lib/types/apiRequests';
import { AttendEventRequest, CreateBonusRequest, Event } from '@/lib/types/apiRequests';
import {
AttendEventResponse,
CreateBonusResponse,
CreateEventResponse,
GetAllEventsResponse,
GetAttendancesForUserResponse,
Expand Down Expand Up @@ -159,3 +160,28 @@ export const uploadEventImage = async (
},
});
};

export const awardBonusPoints = async (
token: string,
user: string,
points: number,
description: string
): Promise<CreateBonusResponse> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.admin.bonus}`;

const requestBody: CreateBonusRequest = {
bonus: {
users: [user],
description,
points,
},
};

const response = await axios.post<CreateBonusResponse>(requestUrl, requestBody, {
headers: {
Authorization: `Bearer ${token}`,
},
});

return response.data;
};
12 changes: 9 additions & 3 deletions src/pages/admin/points.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import { config } from '@/lib';
import { config, showToast } from '@/lib';
import { EventAPI } from '@/lib/api';
import withAccessType from '@/lib/hoc/withAccessType';
import { PermissionService, ValidationService } from '@/lib/services';
import { CookieService, PermissionService, ValidationService } from '@/lib/services';
import { CookieType } from '@/lib/types/enums';
import type { GetServerSideProps, NextPage } from 'next';
import { SubmitHandler, useForm } from 'react-hook-form';
import { AiOutlineMail } from 'react-icons/ai';
Expand All @@ -20,8 +22,11 @@ const AwardPointsPage: NextPage = () => {
formState: { errors },
} = useForm<FormValues>();

const onSubmit: SubmitHandler<FormValues> = () => {
const onSubmit: SubmitHandler<FormValues> = async ({ email, description, points }) => {
// TODO
const token = CookieService.getClientCookie(CookieType.ACCESS_TOKEN);
const response = await EventAPI.awardBonusPoints(token, email, points, description);
showToast(`Successfully awarded bonus points for ${JSON.stringify(response.emails)}`);
};

return (
Expand Down Expand Up @@ -60,6 +65,7 @@ const AwardPointsPage: NextPage = () => {
placeholder="Point Value"
formRegister={register('points', {
required: 'Required',
valueAsNumber: true,
})}
error={errors.points}
/>
Expand Down

0 comments on commit 1b5f445

Please sign in to comment.