Skip to content

Commit

Permalink
fixing types
Browse files Browse the repository at this point in the history
  • Loading branch information
sangdth committed Dec 8, 2023
1 parent bc6a3fc commit 481bee8
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 57 deletions.
5 changes: 2 additions & 3 deletions app/(default)/dashboard/pages/[id]/advanced/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Box, Flex, Skeleton } from '@/components/chakra';
import { getPage } from '@/services/pages';

import { Box, Flex, Skeleton } from '@/components/chakra';
import { DeleteSection } from '../../components/PageForm/DeleteSection';
import { BasicSEO } from '../../components/BasicSEO';
import { BasicSEO, DeleteSection } from '../../components';

type AdvancedSettingsProps = {
params: { id: string };
Expand Down
3 changes: 1 addition & 2 deletions app/(default)/dashboard/pages/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSession } from '@/configs/auth';
import { getPage } from '@/services/pages';
import { redirect } from 'next/navigation';
import { getPage } from '@/services/pages';

import { PageForm } from '../components';

Expand All @@ -27,7 +27,6 @@ export default async function EditPage({ params }: EditPageProps) {
backPath="/dashboard/pages"
title="Edit Page"
data={originalPage}
translatedPages={originalPage.translatedPages}
/>
);
}
2 changes: 2 additions & 0 deletions app/(default)/dashboard/pages/components/PageForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { isEqual } from '@/utils/compare';
import { fetcher } from '@/utils/fetcher';
import slugify from 'slugify';

export * from './DeleteSection';

export type PageFormProps = {
title?: string;
backPath?: string;
Expand Down
2 changes: 1 addition & 1 deletion app/(default)/dashboard/pages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export * from './PageForm';
export * from './PagesTable';
export * from './Translations';
export * from './BasicSEO';
19 changes: 2 additions & 17 deletions app/(default)/dashboard/posts/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,7 @@ type EditPostProps = {
export default async function EditPost({ params }: EditPostProps) {
const { id } = params;

const originalPost = await prisma.post.findUnique({ where: { id } });
const post = await prisma.post.findUnique({ where: { id } });

if (!originalPost) {
return null;
}

const translatedPosts = await prisma.post.findMany({
where: { originalId: id },
});

return (
<PostForm
backPath="/dashboard/posts"
title="Edit Post"
data={originalPost}
translatedPosts={translatedPosts}
/>
);
return <PostForm backPath="/dashboard/posts" title="Edit Post" data={post} />;
}
12 changes: 1 addition & 11 deletions app/(default)/dashboard/posts/components/PostForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ import { DeleteSection } from './DeleteSection';
export type PostFormProps = {
title?: string;
backPath?: string;
data?: Post;
translatedPosts?: Post[];
originalId?: string;
translateTo?: string;
data?: Post | null;
};

export const PostForm = ({
backPath,
title,
data: propsData,
originalId,
translateTo,
}: PostFormProps) => {
const toast = useToast();
const router = useRouter();
Expand All @@ -53,7 +48,6 @@ export const PostForm = ({
title: propsData?.title ?? '',
slug: propsData?.slug ?? '',
content: propsData?.content ?? '',
originalId: propsData?.originalId ?? originalId,
};

const [data, setInputData] = useState(initialData);
Expand Down Expand Up @@ -82,10 +76,6 @@ export const PostForm = ({
router.refresh();
}
} else {
if (originalId && translateTo) {
formData.append('originalId', originalId);
}

const response = await createPost(formData);

if (response) {
Expand Down
16 changes: 2 additions & 14 deletions app/(default)/dashboard/posts/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { PostForm } from '../components';

export default function AddNewPost({
searchParams,
}: {
searchParams: { [key: string]: string };
}) {
const { translateTo, originalId } = searchParams;

return (
<PostForm
title={originalId ? 'Add New Transltation' : 'Add New Post'}
originalId={originalId}
translateTo={translateTo}
/>
);
export default function AddNewPost() {
return <PostForm title="Add New Post" />;
}
1 change: 1 addition & 0 deletions components/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export * from './AccessDenied';
export * from './AddNewButton';
export * from './ClientProviders';
export * from './CustomEditable';
export * from './FormWrapper';
export * from './GoBackButton';
Expand Down
8 changes: 5 additions & 3 deletions components/server/ProfileMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import {
Button,
HStack,
Expand All @@ -11,13 +13,13 @@ import {
} from '@/components/chakra';
import { NextImage, NextLink } from '@/components/client';
import { ChevronDownIcon } from '@/icons';
import { getSession } from '@/configs/auth';
import { useSession } from '@/hooks';

import { LogoutButton } from './LogoutButton';
import { SetColorMode } from './SetColorMode';

export const ProfileMenu = async () => {
const session = await getSession();
export const ProfileMenu = () => {
const { data: session } = useSession();

if (!session) {
return (
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"scripts": {
"prisma": "prisma",
"postinstall": "prisma generate",
"clean": "rimraf node_modules .next dist .react-email && pnpm install",
"clean": "rimraf node_modules .next dist && pnpm install",
"dev": "docker-compose up -d && pnpm watch && docker-compose down",
"dev-servers": "next dev & email dev --port 3002 --dir lib/emails",
"watch": "trap 'exit 0' SIGINT; prisma generate && prisma db push && pnpm dev-servers",
"watch": "trap 'exit 0' SIGINT; prisma generate && prisma db push && next dev",
"build": "prisma generate && next build",
"format": "prettier --write \"**/*.{css,js,json,jsx,ts,tsx}\"",
"start": "next start",
Expand Down
172 changes: 172 additions & 0 deletions prisma/migrations/20231208113631_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('USER', 'ADMIN', 'AUTHOR', 'MANAGER');

-- CreateEnum
CREATE TYPE "PostType" AS ENUM ('DEFAULT', 'AUDIO', 'VIDEO', 'YOUTUBE');

-- CreateTable
CREATE TABLE "Account" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"type" TEXT NOT NULL,
"provider" TEXT NOT NULL,
"providerAccountId" TEXT NOT NULL,
"refresh_token" TEXT,
"access_token" TEXT,
"expires_at" INTEGER,
"token_type" TEXT,
"scope" TEXT,
"id_token" TEXT,
"session_state" TEXT,
"siteId" TEXT,

CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL,
"sessionToken" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"expires" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"name" TEXT,
"email" TEXT,
"emailVerified" TIMESTAMP(3),
"image" TEXT,
"password" TEXT NOT NULL,
"role" "UserRole" NOT NULL DEFAULT 'USER',
"preferences" JSONB NOT NULL DEFAULT '{}',
"confirmCode" TEXT,
"siteId" TEXT,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VerificationToken" (
"identifier" TEXT NOT NULL,
"token" TEXT NOT NULL,
"expires" TIMESTAMP(3) NOT NULL
);

-- CreateTable
CREATE TABLE "Page" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"publishedAt" TIMESTAMP(3),
"title" VARCHAR(255) NOT NULL,
"slug" VARCHAR(255) NOT NULL,
"content" TEXT NOT NULL,
"components" JSONB NOT NULL DEFAULT '{}',
"authorId" TEXT NOT NULL,
"isBlog" BOOLEAN,
"meta" JSONB DEFAULT '[{}]',
"siteId" TEXT,

CONSTRAINT "Page_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Post" (
"id" TEXT NOT NULL,
"title" VARCHAR(255) NOT NULL,
"content" TEXT NOT NULL,
"slug" VARCHAR(255) NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"authorId" TEXT NOT NULL,
"publishedAt" TIMESTAMP(3),
"featuredImage" TEXT,
"siteId" TEXT,
"type" "PostType" DEFAULT 'DEFAULT',

CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tag" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"value" VARCHAR(128) NOT NULL,
"siteId" TEXT,

CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "_PageToTag" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "_PostToTag" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");

-- CreateIndex
CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");

-- CreateIndex
CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token");

-- CreateIndex
CREATE UNIQUE INDEX "Page_slug_key" ON "Page"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "Post_slug_key" ON "Post"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "_PageToTag_AB_unique" ON "_PageToTag"("A", "B");

-- CreateIndex
CREATE INDEX "_PageToTag_B_index" ON "_PageToTag"("B");

-- CreateIndex
CREATE UNIQUE INDEX "_PostToTag_AB_unique" ON "_PostToTag"("A", "B");

-- CreateIndex
CREATE INDEX "_PostToTag_B_index" ON "_PostToTag"("B");

-- AddForeignKey
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Page" ADD CONSTRAINT "Page_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PageToTag" ADD CONSTRAINT "_PageToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Page"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PageToTag" ADD CONSTRAINT "_PageToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PostToTag" ADD CONSTRAINT "_PostToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_PostToTag" ADD CONSTRAINT "_PostToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ generator client {

datasource db {
provider = "postgresql"
url = env("DATA_URL")
url = env("DATABASE_URL")
}

model Account {
Expand Down
2 changes: 1 addition & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prisma } from '@prisma/client';

export type * from '@prisma/client';
export * from '@prisma/client';

export type JsonObject = Prisma.JsonObject;
export type JsonValue = Prisma.JsonValue;
Expand Down
2 changes: 1 addition & 1 deletion types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line
import NextAuth, { DefaultSession } from 'next-auth';
import type { Prisma, User as PrismaUser, UserRole } from '@prisma/client';
import { Prisma, User as PrismaUser, UserRole } from '@prisma/client';

declare module 'next-auth/adapters' {
interface AdapterUser extends PrismaUser {}
Expand Down

0 comments on commit 481bee8

Please sign in to comment.