Skip to content

Commit 355d723

Browse files
committed
2 parents ec59ec3 + ff38454 commit 355d723

File tree

6 files changed

+52
-39
lines changed

6 files changed

+52
-39
lines changed

components/Sections/configs/ConfigCard.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Badge } from '@/components/ui/badge';
1010
import { Avatar, AvatarImage, AvatarFallback } from '@radix-ui/react-avatar';
1111
import { JsonValue } from '@prisma/client/runtime/library';
12-
import ConfigCardControls from "./ConfigCardControls.tsx";
12+
import ConfigCardControls from './ConfigCardControls.tsx';
1313

1414
export type Config = {
1515
id: number;
@@ -39,9 +39,7 @@ export default async function ConfigCard({ config }: { config: Config }) {
3939

4040
return (
4141
<div>
42-
<Card
43-
className="cursor-pointer hover:bg-slate-100/60 transition-colors flex flex-col"
44-
>
42+
<Card className="cursor-pointer hover:bg-slate-100/60 transition-colors flex flex-col">
4543
<CardContent className="flex-grow space-y-2 p-4">
4644
<CardTitle className="text-lg">{config.title}</CardTitle>
4745
<div className="flex flex-wrap gap-2 -ml-1">
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
import { CardFooter } from "@/components/ui/card";
2-
import { useSession } from "next-auth/react"
3-
import UpdateAction from "./UpdateActionButton";
4-
import { Config } from "./ConfigCard";
5-
import DownloadButton from "./DownloadButton";
1+
import { CardFooter } from '@/components/ui/card';
2+
import { useSession } from 'next-auth/react';
3+
import UpdateAction from './UpdateActionButton';
4+
import { Config } from './ConfigCard';
5+
import DownloadButton from './DownloadButton';
66

7-
export default function ConfigCardControls({ config, downloadAction }: { config: Config, downloadAction: () => void }) {
8-
const { data: session } = useSession()
7+
export default function ConfigCardControls({
8+
config,
9+
downloadAction,
10+
}: {
11+
config: Config;
12+
downloadAction: () => void;
13+
}) {
14+
const { data: session } = useSession();
915

1016
const userId = config?.user?.id.toString();
11-
const sessionUserId = (session?.user?.image ?? "").match(/avatars\/(\d+)\//)?.[1] ?? "0";
17+
const sessionUserId =
18+
(session?.user?.image ?? '').match(/avatars\/(\d+)\//)?.[1] ?? '0';
1219

1320
return (
1421
<CardFooter className="p-0">
1522
<DownloadButton downloadAction={downloadAction} />
16-
{
17-
(process.env.NODE_ENV === "development" || userId === sessionUserId) && (
18-
<UpdateAction config={config} />
19-
)
20-
}
23+
{(process.env.NODE_ENV === 'development' || userId === sessionUserId) && (
24+
<UpdateAction config={config} />
25+
)}
2126
</CardFooter>
22-
)
27+
);
2328
}

components/Sections/configs/DeleteAction.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const DeleteAction = ({ configId }: { configId: number }) => {
77
<Button
88
variant="destructive"
99
onClick={() => deleteConfig(configId)}
10-
className='w-full m-0 rounded-tl-none rounded-br-none rounded-tr-none hover:opacity-80 transition-all duration-100'
10+
className="w-full m-0 rounded-tl-none rounded-br-none rounded-tr-none hover:opacity-80 transition-all duration-100"
1111
>
1212
Delete
1313
</Button>
1414
</>
15-
)
16-
}
15+
);
16+
};
1717

1818
export default DeleteAction;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
'use client'
1+
'use client';
22

3-
import { Button } from "@/components/ui/button"
3+
import { Button } from '@/components/ui/button';
44

5-
export default function DownloadButton({ downloadAction }: { downloadAction: () => void }) {
5+
export default function DownloadButton({
6+
downloadAction,
7+
}: {
8+
downloadAction: () => void;
9+
}) {
610
return (
711
<Button
812
onClick={downloadAction}
9-
className='w-full m-0 rounded-tl-none rounded-tr-none hover:opacity-80 transition-all duration-100 bg-[#2b65ca] text-white hover:bg-[#2359b6] rounded-bl-none rounded-br-none'
13+
className="w-full m-0 rounded-tl-none rounded-tr-none hover:opacity-80 transition-all duration-100 bg-[#2b65ca] text-white hover:bg-[#2359b6] rounded-bl-none rounded-br-none"
1014
>
1115
Download
1216
</Button>
13-
)
17+
);
1418
}

components/Sections/configs/UpdateActionButton.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
'use client';
22

33
import { useState, useEffect } from 'react';
44
import { Button } from '@/components/ui/button';
@@ -26,7 +26,7 @@ import {
2626
import { useSession } from 'next-auth/react';
2727
import { updateConfig } from './UpdateConfigAction';
2828
import { deleteConfig } from './DeleteServerAction';
29-
import { type Config } from "./ConfigCard";
29+
import { type Config } from './ConfigCard';
3030

3131
const UpdateAction = ({ config }: { config: Config }) => {
3232
const { toast } = useToast();
@@ -97,7 +97,8 @@ const UpdateAction = ({ config }: { config: Config }) => {
9797
} else {
9898
toast({
9999
title: 'Failed to update config',
100-
description: 'There was an error while updating your config. Please try again!',
100+
description:
101+
'There was an error while updating your config. Please try again!',
101102
variant: 'destructive',
102103
});
103104
}
@@ -113,7 +114,10 @@ const UpdateAction = ({ config }: { config: Config }) => {
113114
};
114115

115116
const renderForm = () => (
116-
<form className="grid items-start gap-4 max-md:px-4" onSubmit={handleSubmit}>
117+
<form
118+
className="grid items-start gap-4 max-md:px-4"
119+
onSubmit={handleSubmit}
120+
>
117121
<div className="grid gap-2">
118122
<Label htmlFor="title">
119123
Title <span className="text-red-500">*</span>
@@ -149,14 +153,12 @@ const UpdateAction = ({ config }: { config: Config }) => {
149153
...formData,
150154
categories: e.target.value
151155
.split(',')
152-
.map((cat: string) => cat.trim())
156+
.map((cat: string) => cat.trim()),
153157
})
154158
}
155159
/>
156160
</div>
157-
<Button type="submit">
158-
Submit
159-
</Button>
161+
<Button type="submit">Submit</Button>
160162
<Button
161163
variant="destructive"
162164
onClick={async (e) => {
@@ -175,7 +177,8 @@ const UpdateAction = ({ config }: { config: Config }) => {
175177
} else {
176178
toast({
177179
title: 'Failed to delete config',
178-
description: 'There was an error while deleting your config. Please try again!',
180+
description:
181+
'There was an error while deleting your config. Please try again!',
179182
variant: 'destructive',
180183
});
181184
}
@@ -240,7 +243,7 @@ const UpdateAction = ({ config }: { config: Config }) => {
240243
<Button
241244
variant="secondary"
242245
onClick={() => setOpen(true)}
243-
className='w-full m-0 rounded-tl-none rounded-tr-none hover:opacity-80 transition-all duration-100 bg-[#4482ef] text-white hover:bg-[#4471efe6] rounded-br-none rounded-bl-none'
246+
className="w-full m-0 rounded-tl-none rounded-tr-none hover:opacity-80 transition-all duration-100 bg-[#4482ef] text-white hover:bg-[#4471efe6] rounded-br-none rounded-bl-none"
244247
>
245248
Update
246249
</Button>

components/Sections/configs/UpdateConfigAction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ type ConfigID = number;
88

99
type UpdatedConfig = Omit<Config, 'user' | 'id'> & { userId: number };
1010

11-
export async function updateConfig(configId: ConfigID, updatedData: UpdatedConfig) {
11+
export async function updateConfig(
12+
configId: ConfigID,
13+
updatedData: UpdatedConfig,
14+
) {
1215
const { title, description, categories, config, userId } = updatedData;
1316
if (!configId) {
1417
throw new Error('Config ID is required');
@@ -32,14 +35,14 @@ export async function updateConfig(configId: ConfigID, updatedData: UpdatedConfi
3235
description: description,
3336
categories: categories,
3437
config: {
35-
...(typeof config === 'object' && config !== null ? config : {})
38+
...(typeof config === 'object' && config !== null ? config : {}),
3639
},
3740
user: {
3841
connect: {
3942
id: userId,
4043
},
4144
},
42-
}
45+
},
4346
});
4447

4548
revalidatePath('/configs');

0 commit comments

Comments
 (0)