From 82d8cddd4fd02fc13605a2c01cdc7ebc1106510a Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 31 Jul 2024 23:08:15 -0400 Subject: [PATCH 01/22] feat: Add donor features --- locales/en.json | 1 + prisma/schema.prisma | 3 +- src/components/account/DonorButton.jsx | 43 ++++++++++++++++ src/components/user/UserInformationCard.jsx | 3 ++ src/pages/api/account/donor.js | 54 +++++++++++++++++++++ src/pages/user/[username]/index.jsx | 1 + 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/components/account/DonorButton.jsx create mode 100644 src/pages/api/account/donor.js diff --git a/locales/en.json b/locales/en.json index 68ea126..58e3c13 100644 --- a/locales/en.json +++ b/locales/en.json @@ -17,6 +17,7 @@ "hidden": "Hidden", "administrator": "Administrator", "moderator": "Moderator", + "donor": "Donator", "play_log": "Play Log", "registered_on": "Registered", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c99015a..7f36aa3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -126,10 +126,11 @@ model user { created_at DateTime @default(dbgenerated("CURRENT_TIMESTAMP(3)")) updated_at DateTime @default(dbgenerated("CURRENT_TIMESTAMP(3)")) badge String? @db.VarChar(50) + language String @default("en") @db.VarChar(11) isBanned Int @default(0) @db.SmallInt isPublic Int @default(1) @db.SmallInt publicOverride Int? @db.SmallInt - language String @default("en") @db.VarChar(11) + isDonor Boolean @default(false) accounts accounts[] banned_user banned_user[] game_sessions game_sessions[] diff --git a/src/components/account/DonorButton.jsx b/src/components/account/DonorButton.jsx new file mode 100644 index 0000000..f205b72 --- /dev/null +++ b/src/components/account/DonorButton.jsx @@ -0,0 +1,43 @@ +import { React, useState } from 'react' +import { useRouter } from 'next/router' +import { toast } from 'react-toastify' +import useInfo from '@/lib/swr-hooks/useInfo' +import ConfirmationModal from '../shared/ConfirmationModal' +import { Button, Form } from 'react-bootstrap' +import PropTypes from 'prop-types' + +export default function DonorButton ({ isDonor, id }) { + const router = useRouter() + const { mutate } = useInfo() + + const setDonor = async (status) => { + const response = await fetch('/api/account/donor', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + status, + user: id + }) + }) + if (response.status === 200) { + toast.success('The account has been set to donor.') + mutate() + router.reload() + } else { + toast.error('An error occured, please try again later.') + } + } + + return ( + + ) +} + +DonorButton.propTypes = { + id: PropTypes.number.isRequired, + isDonor: PropTypes.bool.isRequired +} diff --git a/src/components/user/UserInformationCard.jsx b/src/components/user/UserInformationCard.jsx index c6c34bb..6f6cd20 100644 --- a/src/components/user/UserInformationCard.jsx +++ b/src/components/user/UserInformationCard.jsx @@ -17,6 +17,7 @@ import BanAccountButton from '../account/BanAccountButton' import ForceHiddenAccountButton from '../account/ForceHiddenAccountButton' import LanguageContext from '../shared/LanguageContext' import LocalizedString from '../shared/LocalizedString' +import DonorButton from '@/components/account/DonorButton' function UserInformationCard ({ user, isLoggedIn, isAdmin, isMod }) { return ( @@ -29,6 +30,7 @@ function UserInformationCard ({ user, isLoggedIn, isAdmin, isMod }) { {(user.publicOverride === 0 || (user.publicOverride === 1 && isMod)) && ()} {user.role === 'admin' && ()} {user.role === 'mod' && ()} + {user.isDonor === true && ()}