-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refact some part of code base
- Loading branch information
1 parent
df243b6
commit 1077095
Showing
35 changed files
with
407 additions
and
206 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
"use server"; | ||
import { revalidatePath } from "next/cache"; | ||
import { userAction } from "@/lib/next-safe-action"; | ||
import { formRepositorySchema } from "@/components/organisms/_forms/addrepository.schema"; | ||
import repositoryService from "@/services/repository.service"; | ||
import * as z from "zod"; | ||
|
||
export const addRepository = userAction( | ||
formRepositorySchema, | ||
async (data, ctx) => { | ||
try { | ||
await repositoryService.postRepository({ | ||
...data, | ||
createdBy: ctx.session.user.id, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
const schema = z.object({ | ||
url: z.string().url(), | ||
description: z.string(), | ||
}); | ||
|
||
revalidatePath("/"); | ||
}, | ||
); | ||
export const addRepository = userAction(schema, async (data, ctx) => { | ||
try { | ||
await repositoryService.postRepository({ | ||
...data, | ||
createdBy: ctx.session.user.id, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
|
||
revalidatePath("/repositories"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use server"; | ||
import { revalidatePath } from "next/cache"; | ||
import { adminAction } from "@/lib/next-safe-action"; | ||
import repositoryService from "@/services/repository.service"; | ||
import * as z from "zod"; | ||
|
||
const schema = z.object({ | ||
id: z.number(), | ||
}); | ||
|
||
export const hideRepository = adminAction(schema, async (data) => { | ||
try { | ||
await repositoryService.hideRepository(data.id); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
|
||
revalidatePath("/"); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use server"; | ||
|
||
import { adminAction } from "@/lib/next-safe-action"; | ||
import adminService from "@/services/admin.service"; | ||
import { revalidatePath } from "next/cache"; | ||
import { z } from "zod"; | ||
|
||
const schema = z.object({ | ||
repositoryId: z.number(), | ||
}); | ||
|
||
export const removeRepositoryComments = adminAction(schema, async (data) => { | ||
try { | ||
await adminService.removeRepositoryComments(data.repositoryId); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
|
||
revalidatePath(`/repositories/${data.repositoryId}`); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
"use server"; | ||
import { revalidatePath } from "next/cache"; | ||
import { userAction } from "@/lib/next-safe-action"; | ||
import { dataSharingAgreementSchema } from "@/components/organisms/_forms/dataSharingAgreement.schema"; | ||
import userService from "@/services/user.service"; | ||
import * as z from "zod"; | ||
|
||
export const updateAgreement = userAction( | ||
dataSharingAgreementSchema, | ||
async (data, ctx) => { | ||
try { | ||
await userService.updateAgreement(ctx.session.user, data.agreement!); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
const schema = z.object({ | ||
agreement: z.boolean().default(false).optional(), | ||
}); | ||
|
||
revalidatePath("/"); | ||
}, | ||
); | ||
export const updateAgreement = userAction(schema, async (data, ctx) => { | ||
try { | ||
await userService.updateAgreement(ctx.session.user, data.agreement!); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
|
||
revalidatePath("/"); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { PropsWithChildren } from "react"; | ||
|
||
export default function RepositoryCommentLayout({ | ||
children, | ||
}: PropsWithChildren) { | ||
return <div className="m-auto max-w-3xl py-12">{children}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
import Link from "next/link"; | ||
import { ProfileAvatar } from "@/components/molecules/Avatar"; | ||
import { CommentMessages } from "@/components/organisms/CommentMessages"; | ||
import { AddCommentForm } from "@/components/organisms/_forms/addcomment.form"; | ||
import repositoryService from "@/services/repository.service"; | ||
import React from "react"; | ||
|
||
export default async function RepositoryCommentPage({ | ||
params, | ||
}: { | ||
params: { repositoryId: number }; | ||
}) { | ||
const repository = await repositoryService.getRepository( | ||
Number(params.repositoryId), | ||
); | ||
const initialComments = await repositoryService.getCommentsByRepositoryId( | ||
Number(params.repositoryId), | ||
); | ||
|
||
if (!repository) { | ||
return <div>Repository not found</div>; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1>Comments</h1> | ||
<div className="space-y-12"> | ||
<div className="flex items-center space-x-4"> | ||
<ProfileAvatar | ||
pictureUrl={repository.ownerAvatarUrl} | ||
alt={repository.repositoryName} | ||
/> | ||
<div className="flex flex-col"> | ||
<Link | ||
href={repository.url} | ||
className="text-xl font-semibold hover:underline" | ||
target="_blank" | ||
> | ||
{repository?.repositoryName} | ||
</Link> | ||
<span className="text-sm"> | ||
Published by{" "} | ||
{repository.createdBy.username ?? repository.createdBy.name} | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<CommentMessages | ||
initialComments={initialComments} | ||
repositoryId={params.repositoryId} | ||
/> | ||
<AddCommentForm repositoryId={Number(params.repositoryId)} /> | ||
</> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Link from "next/link"; | ||
import { ProfileAvatar } from "@/components/molecules/Avatar"; | ||
import { calculateCommentCreatedRange } from "@/lib/utils"; | ||
import type { Comment } from "@/types/prisma.type"; | ||
|
||
type Props = { | ||
comment: Comment; | ||
}; | ||
|
||
export const CardComment = ({ comment }: Props) => { | ||
return ( | ||
<div className="flex flex-col space-y-4 overflow-hidden rounded-md border border-card bg-default px-4 py-2 shadow"> | ||
<div className="flex items-center gap-2"> | ||
<ProfileAvatar pictureUrl={comment.createdBy.image ?? ""} /> | ||
<div className="flex space-x-2"> | ||
<Link | ||
href="#" | ||
className="text-sm font-semibold hover:text-[#2F81F7] hover:underline" | ||
target="_blank" | ||
> | ||
{comment.createdBy.username ?? comment.createdBy.name} | ||
</Link> | ||
<span className="cursor-pointer text-sm text-[#848D86] hover:text-[#2F81F7] hover:underline"> | ||
{calculateCommentCreatedRange(comment.createdAt)} ago | ||
</span> | ||
</div> | ||
</div> | ||
<div className="text-base">{comment.content}</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.