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

Implement award points page #122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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,
GetFutureEventsResponse,
Expand Down Expand Up @@ -145,3 +146,28 @@ export const uploadEventImage = async (
},
});
};

export const awardBonusPoints = async (
token: string,
user: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a username or user UUID?

Suggested change
user: string,
username: string,
Suggested change
user: string,
user: UUID,

(or userId: UUID)

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

const requestBody: CreateBonusRequest = {
bonus: {
users: [user],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should have awardBonusPoints accept a list of users since the backend supports it, and the function returns a list of emails rather than just one

description,
points,
},
};

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

return response.data;
};
13 changes: 9 additions & 4 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,10 @@ const AwardPointsPage: NextPage = () => {
formState: { errors },
} = useForm<FormValues>();

const onSubmit: SubmitHandler<FormValues> = () => {
// TODO
const onSubmit: SubmitHandler<FormValues> = async ({ email, description, points }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap this in an admin event manager function for repo conventions and also error handling

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 +64,7 @@ const AwardPointsPage: NextPage = () => {
placeholder="Point Value"
formRegister={register('points', {
required: 'Required',
valueAsNumber: true,
})}
error={errors.points}
/>
Expand Down