-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
|
@@ -145,3 +146,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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you should have |
||
description, | ||
points, | ||
}, | ||
}; | ||
|
||
const response = await axios.post<CreateBonusResponse>(requestUrl, requestBody, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; |
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'; | ||
|
@@ -20,8 +22,10 @@ const AwardPointsPage: NextPage = () => { | |
formState: { errors }, | ||
} = useForm<FormValues>(); | ||
|
||
const onSubmit: SubmitHandler<FormValues> = () => { | ||
// TODO | ||
const onSubmit: SubmitHandler<FormValues> = async ({ email, description, points }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
@@ -60,6 +64,7 @@ const AwardPointsPage: NextPage = () => { | |
placeholder="Point Value" | ||
formRegister={register('points', { | ||
required: 'Required', | ||
valueAsNumber: true, | ||
})} | ||
error={errors.points} | ||
/> | ||
|
There was a problem hiding this comment.
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?
(or
userId: UUID
)