Skip to content

Commit e4480ff

Browse files
🌟 Allies
1 parent f35ae26 commit e4480ff

File tree

23 files changed

+1370
-293
lines changed

23 files changed

+1370
-293
lines changed

‎components/input.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ type Props = {
1212
textarea?: boolean | false
1313
id?: string;
1414
type?: string | "text";
15+
value?: string
1516
};
1617

1718
const Input = React.forwardRef<
1819
HTMLInputElement | HTMLTextAreaElement,
1920
Props & ReturnType<UseFormRegister<any>>
20-
>(({ placeholder, label, classoverride, id, onChange, onBlur, name, type, textarea, append, prepend, disabled }, ref) => {
21+
>(({ placeholder, label, classoverride, id, onChange, onBlur, name, type, textarea, append, prepend, disabled, value }, ref) => {
2122
const { formState: { errors } } = useFormContext();
2223
return (
2324
<div className="mb-3">
@@ -40,6 +41,7 @@ const Input = React.forwardRef<
4041
onChange={onChange}
4142
onBlur={onBlur}
4243
name={name}
44+
value={value}
4345
ref={(ref as any)}
4446
className={
4547
`text-gray-600 dark:text-white flex-1 rounded-lg p-2 border-2 border-gray-300 dark:border-gray-500 w-full bg-gray-50 disabled:bg-gray-200 focus-visible:outline-none dark:bg-gray-700 ${prepend ? 'rounded-l-none' : 'rounded-l-lg'} ${append ? 'rounded-r-none' : 'rounded-r-lg'} ` + classoverride + `${errors[name] ? " focus-visible:ring-red-500 focus-visible:border-red-500" : "focus-visible:ring-blue-500 focus-visible:border-blue-500"}`
@@ -57,6 +59,7 @@ const Input = React.forwardRef<
5759
onBlur={onBlur}
5860
name={name}
5961
ref={(ref as any)}
62+
value={value}
6063
className={
6164
"text-gray-600 dark:text-white rounded-lg p-2 border-2 border-gray-300 dark:border-gray-500 w-full bg-gray-50 focus-visible:outline-none dark:bg-gray-700 " + classoverride + `${errors[name] ? " focus-visible:ring-red-500 focus-visible:border-red-500" : "focus-visible:ring-blue-500 focus-visible:border-blue-500"}`
6265
}

‎components/settings/general/allies.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const Color: FC<props> = (props) => {
4040

4141
return (
4242
<div className="z-10 relative">
43-
<p> Color </p>
4443
<Input type="number" value={count} onChange={(e) => setCount(parseInt(e.target.value))} label="Minimum rep count" placeholder="1"/>
4544
<Button onClick={() => updateAllyCount(count)} classoverride="mt-2"> Save</Button>
4645
</div>

‎components/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const Topbar: NextPage = () => {
3131
current: false,
3232
},
3333
{
34-
name: "Allys",
35-
href: "/workspace/[id]/allys",
34+
name: "Allies",
35+
href: "/workspace/[id]/allies",
3636
icon: IconBuildingCommunity,
3737

3838
},
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { fetchworkspace, getConfig, setConfig } from '@/utils/configEngine'
4+
import prisma, { inactivityNotice } from '@/utils/database';
5+
import { withSessionRoute } from '@/lib/withSession'
6+
import { withPermissionCheck } from '@/utils/permissionsManager'
7+
import { getUsername, getThumbnail, getDisplayName } from '@/utils/userinfoEngine'
8+
import * as noblox from 'noblox.js'
9+
type Data = {
10+
success: boolean
11+
error?: string
12+
quota?: any
13+
}
14+
15+
export default withPermissionCheck(handler, 'manage_alliances');
16+
17+
export async function handler(
18+
req: NextApiRequest,
19+
res: NextApiResponse<Data>
20+
) {
21+
if (req.method !== 'DELETE') return res.status(405).json({ success: false, error: 'Method not allowed' })
22+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
23+
if (!req.query.aid) return res.status(400).json({ success: false, error: 'Missing ally id' });
24+
if (typeof req.query.aid !== 'string') return res.status(400).json({ success: false, error: 'Invalid ally id' })
25+
26+
27+
try {
28+
await prisma.ally.delete({
29+
where: {
30+
id: String(req.query.aid)
31+
}
32+
});
33+
34+
35+
return res.status(200).json({ success: true });
36+
} catch (error) {
37+
console.error(error);
38+
return res.status(500).json({ success: false, error: "Something went wrong" });
39+
}
40+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { fetchworkspace, getConfig, setConfig } from '@/utils/configEngine'
4+
import prisma, { inactivityNotice } from '@/utils/database';
5+
import { withSessionRoute } from '@/lib/withSession'
6+
import { withPermissionCheck } from '@/utils/permissionsManager'
7+
import { getUsername, getThumbnail, getDisplayName } from '@/utils/userinfoEngine'
8+
import * as noblox from 'noblox.js'
9+
type Data = {
10+
success: boolean
11+
error?: string
12+
ally?: any
13+
}
14+
15+
export default withPermissionCheck(handler, 'manage_alliances');
16+
17+
export async function handler(
18+
req: NextApiRequest,
19+
res: NextApiResponse<Data>
20+
) {
21+
if (req.method !== 'PATCH') return res.status(405).json({ success: false, error: 'Method not allowed' })
22+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
23+
if (!req.query.aid) return res.status(400).json({ success: false, error: 'Missing ally id' });
24+
if (typeof req.query.aid !== 'string') return res.status(400).json({ success: false, error: 'Invalid ally id' })
25+
const { notes } = req.body
26+
if(!notes) return res.status(400).json({ success: false, error: 'Missing content' })
27+
28+
29+
try {
30+
const ally: any = await prisma.ally.updateMany({
31+
where: {
32+
id: String(req.query.aid),
33+
workspaceGroupId: parseInt(req.query.id as string)
34+
},
35+
data: {
36+
notes: notes
37+
}
38+
});
39+
40+
41+
return res.status(200).json({ success: true, ally: ally });
42+
} catch (error) {
43+
console.error(error);
44+
return res.status(500).json({ success: false, error: "Something went wrong" });
45+
}
46+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { fetchworkspace, getConfig, setConfig } from '@/utils/configEngine'
4+
import prisma, { inactivityNotice } from '@/utils/database';
5+
import { withSessionRoute } from '@/lib/withSession'
6+
import { withPermissionCheck } from '@/utils/permissionsManager'
7+
import { getUsername, getThumbnail, getDisplayName } from '@/utils/userinfoEngine'
8+
import * as noblox from 'noblox.js'
9+
type Data = {
10+
success: boolean
11+
error?: string
12+
ally?: any
13+
}
14+
15+
export default withPermissionCheck(handler, 'manage_alliances');
16+
17+
export async function handler(
18+
req: NextApiRequest,
19+
res: NextApiResponse<Data>
20+
) {
21+
if (req.method !== 'PATCH') return res.status(405).json({ success: false, error: 'Method not allowed' })
22+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
23+
if (!req.query.aid) return res.status(400).json({ success: false, error: 'Missing ally id' });
24+
if (typeof req.query.aid !== 'string') return res.status(400).json({ success: false, error: 'Invalid ally id' })
25+
const { reps } = req.body
26+
if (reps.length < 1) return res.status(400).json({ success: false, error: 'You need at least 1 rep' })
27+
const aid = req.query.aid
28+
if(!reps) return res.status(400).json({ success: false, error: 'Missing content' })
29+
30+
31+
try {
32+
33+
34+
await prisma.ally.update({
35+
where: {
36+
id: String(req.query.aid)
37+
},
38+
data: {
39+
reps: {
40+
set: reps.map(( user: Number ) => ({ userid: BigInt(user as number) }))
41+
}
42+
}
43+
})
44+
45+
46+
return res.status(200).json({ success: true });
47+
} catch (error) {
48+
console.error(error);
49+
return res.status(500).json({ success: false, error: "Something went wrong" });
50+
}
51+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { fetchworkspace, getConfig, setConfig } from '@/utils/configEngine'
4+
import prisma, { allyVisit } from '@/utils/database';
5+
import { withSessionRoute } from '@/lib/withSession'
6+
import { withPermissionCheck } from '@/utils/permissionsManager'
7+
import { getUsername, getThumbnail, getDisplayName } from '@/utils/userinfoEngine'
8+
import * as noblox from 'noblox.js'
9+
type Data = {
10+
success: boolean
11+
error?: string
12+
ally?: any
13+
}
14+
15+
export default withPermissionCheck(handler, 'manage_alliances');
16+
17+
export async function handler(
18+
req: NextApiRequest,
19+
res: NextApiResponse<Data>
20+
) {
21+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
22+
if (!req.query.vid) return res.status(400).json({ success: false, error: 'Missing ally id' });
23+
if (typeof req.query.aid !== 'string') return res.status(400).json({ success: false, error: 'Invalid ally id' })
24+
if(req.method == "DELETE") {
25+
try {
26+
// @ts-ignore
27+
const visit = await prisma.allyVisit.delete({
28+
where: {
29+
id: req.query.vid
30+
}
31+
})
32+
33+
34+
return res.status(200).json({ success: true });
35+
} catch (error) {
36+
console.error(error);
37+
return res.status(500).json({ success: false, error: "Something went wrong" });
38+
}
39+
} else if (req.method == "PATCH") {
40+
try {
41+
if(!req.body.name || !req.body.time) return res.status(400).json({ success: false, error: 'Missing data' })
42+
43+
// @ts-ignore
44+
const visit = await prisma.allyVisit.update({
45+
where: {
46+
id: req.query.vid
47+
},
48+
data: {
49+
name: req.body.name,
50+
time: new Date(req.body.time)
51+
}
52+
})
53+
54+
55+
return res.status(200).json({ success: true });
56+
} catch (error) {
57+
console.error(error);
58+
return res.status(500).json({ success: false, error: "Something went wrong" });
59+
}
60+
} else {
61+
return res.status(405).json({ success: false, error: 'Method not allowed' })
62+
}
63+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import { fetchworkspace, getConfig, setConfig } from '@/utils/configEngine'
4+
import prisma, { inactivityNotice } from '@/utils/database';
5+
import { withSessionRoute } from '@/lib/withSession'
6+
import { withPermissionCheck } from '@/utils/permissionsManager'
7+
import { getUsername, getThumbnail, getDisplayName } from '@/utils/userinfoEngine'
8+
import * as noblox from 'noblox.js'
9+
type Data = {
10+
success: boolean
11+
error?: string
12+
ally?: any
13+
}
14+
15+
export default withPermissionCheck(handler, 'manage_alliances');
16+
17+
export async function handler(
18+
req: NextApiRequest,
19+
res: NextApiResponse<Data>
20+
) {
21+
if (req.method !== 'POST') return res.status(405).json({ success: false, error: 'Method not allowed' })
22+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
23+
if (!req.query.aid) return res.status(400).json({ success: false, error: 'Missing ally id' });
24+
if (typeof req.query.aid !== 'string') return res.status(400).json({ success: false, error: 'Invalid ally id' })
25+
const { name, time } = req.body
26+
if(!name || !time) return res.status(400).json({ success: false, error: 'Missing content' })
27+
28+
29+
try {
30+
const visit = await prisma.allyVisit.create({
31+
data: {
32+
hostId: req.session.userid,
33+
allyId: req.query.aid,
34+
name: name,
35+
time: new Date(time)
36+
}
37+
})
38+
39+
40+
return res.status(200).json({ success: true });
41+
} catch (error) {
42+
console.error(error);
43+
return res.status(500).json({ success: false, error: "Something went wrong" });
44+
}
45+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2+
import type { NextApiRequest, NextApiResponse } from 'next'
3+
import prisma from '@/utils/database';
4+
import { withPermissionCheck } from '@/utils/permissionsManager'
5+
import moment from 'moment';
6+
import * as noblox from 'noblox.js'
7+
type Data = {
8+
success: boolean
9+
error?: string
10+
}
11+
12+
export default withPermissionCheck(handler, 'manage_alliances');
13+
14+
export async function handler(
15+
req: NextApiRequest,
16+
res: NextApiResponse<Data>
17+
) {
18+
if (req.method !== 'POST') return res.status(405).json({ success: false, error: 'Method not allowed' })
19+
if (!req.session.userid) return res.status(401).json({ success: false, error: 'Not logged in' });
20+
if (!req.body.groupId || !req.body.reps) return res.status(400).json({ success: false, error: "Missing data" });
21+
22+
try {
23+
const date = new Date();
24+
const groupId = req.body.groupId
25+
const notes = req.body.notes || "This note is empty"
26+
const reps = req.body.reps
27+
28+
const groupInfo = await noblox.getGroup(groupId)
29+
if(!groupInfo) return res.status(400).json({ success: false, error: 'Invalid group ID' })
30+
const groupIcon = await noblox.getLogo(groupId)
31+
32+
if(reps.length < 1) return res.status(400).json({ success: false, error: 'At least 1 rep required' })
33+
34+
await prisma.ally.create({
35+
data: {
36+
notes: [notes],
37+
workspaceGroupId: parseInt(req.query.id as string),
38+
groupId: groupId,
39+
name: groupInfo.name,
40+
icon: groupIcon,
41+
reps: {
42+
connect: reps.map(( user: Number ) => ({ userid: BigInt(user as number) }))
43+
}
44+
}
45+
});
46+
47+
return res.status(200).json({ success: true });
48+
} catch (error) {
49+
console.error(error);
50+
return res.status(500).json({ success: false, error: "Something went wrong" });
51+
}
52+
}

0 commit comments

Comments
 (0)