From 4724a1c22947f372aeaf269f027f5756f5c29ab7 Mon Sep 17 00:00:00 2001 From: pdovhomilja <41537049+pdovhomilja@users.noreply.github.com> Date: Fri, 3 Nov 2023 12:00:33 +0100 Subject: [PATCH] Updated - React email - set all components to "use client" Fix production build Added sharp npm form image - it was recommended fix some types Updated Dockerfile --- Dockerfile | 13 +- actions/crm/get-opportunities.ts | 4 +- actions/get-notions.ts | 2 +- actions/get-users.ts | 2 +- actions/projects/get-tasks.ts | 6 +- app/[locale]/(auth)/pending/page.tsx | 5 +- .../register/components/RegisterComponent.tsx | 12 +- .../(routes)/admin/_components/GptCard.tsx | 7 +- .../(routes)/admin/forms/SetGptModel.tsx | 8 +- app/[locale]/(routes)/editor/page.tsx | 12 - app/api/generate/route.ts | 83 --- emails/DemoTemplate.tsx | 1 + emails/InviteUser.tsx | 3 +- emails/NewTaskComment.tsx | 4 +- emails/NewTaskFromCRM.tsx | 3 +- emails/NewTaskFromCRMToWatchers.tsx | 3 +- emails/NewTaskFromProject.tsx | 3 +- emails/PasswordReset.tsx | 4 +- package-lock.json | 505 +++++++++--------- 19 files changed, 300 insertions(+), 380 deletions(-) delete mode 100644 app/[locale]/(routes)/editor/page.tsx delete mode 100644 app/api/generate/route.ts diff --git a/Dockerfile b/Dockerfile index 5a7e8a8..090f212 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM node:18-alpine AS deps +FROM node:20.9.0-alpine AS deps WORKDIR /app COPY package*.json ./ RUN npm install -FROM node:18-alpine AS BUILD_IMAGE +FROM node:20.9.0-alpine AS BUILD_IMAGE WORKDIR /app @@ -15,7 +15,7 @@ RUN npm run build RUN rm -rf node_modules RUN npm install -FROM node:18-alpine +FROM node:20.9.0-alpine ENV NODE_ENV production @@ -27,7 +27,10 @@ COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/package.json /app/package-loc COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/node_modules ./node_modules COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/public ./public COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/.next ./.next -COPY --from=BUILD_IMAGE --chown=nextjs:nodejs /app/.env.local ./.env.local + +# Copy .env and .env.local to the final image +COPY --from=deps --chown=nextjs:nodejs /app/.env ./.env +COPY --from=deps --chown=nextjs:nodejs /app/.env.local ./.env.local USER nextjs @@ -35,4 +38,4 @@ EXPOSE 3000 CMD [ "npm", "start" ] -#docker build --build-arg ENV_FILE=.env -t myimage . \ No newline at end of file +#docker build --build-arg ENV_FILE=.env -t myimage . diff --git a/actions/crm/get-opportunities.ts b/actions/crm/get-opportunities.ts index 910d65b..1551347 100644 --- a/actions/crm/get-opportunities.ts +++ b/actions/crm/get-opportunities.ts @@ -37,7 +37,7 @@ export const getOpportunitiesByMonth = async () => { {} ); - const chartData = Object.keys(opportunitiesByMonth).map((month) => { + const chartData = Object.keys(opportunitiesByMonth).map((month: any) => { return { name: month, Number: opportunitiesByMonth[month], @@ -73,7 +73,7 @@ export const getOpportunitiesByStage = async () => { {} ); - const chartData = Object.keys(opportunitiesByStage).map((stage) => { + const chartData = Object.keys(opportunitiesByStage).map((stage: any) => { return { name: stage, Number: opportunitiesByStage[stage], diff --git a/actions/get-notions.ts b/actions/get-notions.ts index 0b8131e..0b3b9fa 100644 --- a/actions/get-notions.ts +++ b/actions/get-notions.ts @@ -83,7 +83,7 @@ export const getNotions = async (): Promise => { }); const notionItems = databases.map( - (item) => + (item:any) => ({ id: item.id, createdAt: moment(item.created_time).format("YYYY-MM-DD"), diff --git a/actions/get-users.ts b/actions/get-users.ts index 825820d..2165fe9 100644 --- a/actions/get-users.ts +++ b/actions/get-users.ts @@ -43,7 +43,7 @@ export const getUsersByMonth = async () => { return acc; }, {}); - const chartData = Object.keys(usersByMonth).map((month) => { + const chartData = Object.keys(usersByMonth).map((month: any) => { return { name: month, Number: usersByMonth[month], diff --git a/actions/projects/get-tasks.ts b/actions/projects/get-tasks.ts index 8bf11cb..cb1b92c 100644 --- a/actions/projects/get-tasks.ts +++ b/actions/projects/get-tasks.ts @@ -35,7 +35,7 @@ export const getTasks = async () => { //Filtering tasks by section and board const sections = await prismadb.sections.findMany({ where: { - OR: boards.map((board:any) => { + OR: boards.map((board: any) => { return { board: board.id, }; @@ -45,7 +45,7 @@ export const getTasks = async () => { const data = await prismadb.tasks.findMany({ where: { - OR: sections.map((section:any) => { + OR: sections.map((section: any) => { return { section: section.id, }; @@ -84,7 +84,7 @@ export const getTasksByMonth = async () => { return acc; }, {}); - const chartData = Object.keys(tasksByMonth).map((month) => { + const chartData = Object.keys(tasksByMonth).map((month: any) => { return { name: month, Number: tasksByMonth[month], diff --git a/app/[locale]/(auth)/pending/page.tsx b/app/[locale]/(auth)/pending/page.tsx index fdffa4c..e8ef7a3 100644 --- a/app/[locale]/(auth)/pending/page.tsx +++ b/app/[locale]/(auth)/pending/page.tsx @@ -5,9 +5,10 @@ import { getServerSession } from "next-auth"; import Link from "next/link"; import { redirect } from "next/navigation"; import TryAgain from "./components/TryAgain"; +import { Users } from "@prisma/client"; const PendingPage = async () => { - const adminUsers = await prismadb.users.findMany({ + const adminUsers: Users[] = await prismadb.users.findMany({ where: { is_admin: true, userStatus: "ACTIVE", @@ -39,7 +40,7 @@ const PendingPage = async () => {

Admin List

{adminUsers && - adminUsers?.map((user) => ( + adminUsers?.map((user: Users) => (
- {["en", "de", "cz"].map((lng, index) => ( - - {t("locale", { locale: lng })} - - ))} + {["en", "de", "cz"].map( + (lng: string, index: number) => ( + + {t("locale", { locale: lng })} + + ) + )} diff --git a/app/[locale]/(routes)/admin/_components/GptCard.tsx b/app/[locale]/(routes)/admin/_components/GptCard.tsx index c4d5271..9998b3e 100644 --- a/app/[locale]/(routes)/admin/_components/GptCard.tsx +++ b/app/[locale]/(routes)/admin/_components/GptCard.tsx @@ -10,9 +10,10 @@ import { prismadb } from "@/lib/prisma"; import SetGptModel from "../forms/SetGptModel"; import OnTestButton from "./OnTestButton"; +import { gpt_models } from "@prisma/client"; const GptCard = async () => { - const gptModels = await prismadb.gpt_models.findMany(); + const gptModels: gpt_models[] = await prismadb.gpt_models.findMany(); //console.log(gptModels, "gptModels"); return ( @@ -24,8 +25,8 @@ const GptCard = async () => { { //filter in gptModels where status = ACTIVE gptModels - .filter((model) => model.status === "ACTIVE") - .map((model) => model.model) + .filter((model: gpt_models) => model.status === "ACTIVE") + .map((model: gpt_models) => model.model) } diff --git a/app/[locale]/(routes)/admin/forms/SetGptModel.tsx b/app/[locale]/(routes)/admin/forms/SetGptModel.tsx index 12a25ab..5d52890 100644 --- a/app/[locale]/(routes)/admin/forms/SetGptModel.tsx +++ b/app/[locale]/(routes)/admin/forms/SetGptModel.tsx @@ -25,11 +25,17 @@ import { import { toast } from "@/components/ui/use-toast"; import updateModel from "@/actions/admin/update-gpt-model"; import { useRouter } from "next/navigation"; +import { gpt_models } from "@prisma/client"; const FormSchema = z.object({ model: z.string().min(10).max(30), }); +type Model = { + id: string; + model: string; +}; + const SetGptModel = ({ models }: any) => { const router = useRouter(); @@ -70,7 +76,7 @@ const SetGptModel = ({ models }: any) => { - {models.map((model: any) => ( + {models.map((model: Model) => ( {model.model} diff --git a/app/[locale]/(routes)/editor/page.tsx b/app/[locale]/(routes)/editor/page.tsx deleted file mode 100644 index 46f55c8..0000000 --- a/app/[locale]/(routes)/editor/page.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from "react"; -import { Editor } from "novel"; - -const EditorPage = () => { - return ( -
- -
- ); -}; - -export default EditorPage; diff --git a/app/api/generate/route.ts b/app/api/generate/route.ts deleted file mode 100644 index 7f4cc02..0000000 --- a/app/api/generate/route.ts +++ /dev/null @@ -1,83 +0,0 @@ -import OpenAI from "openai"; -import { OpenAIStream, StreamingTextResponse } from "ai"; -import { kv } from "@vercel/kv"; -import { Ratelimit } from "@upstash/ratelimit"; - -// Create an OpenAI API client (that's edge friendly!) -const openai = new OpenAI({ - apiKey: process.env.OPENAI_API_KEY || "", -}); - -// IMPORTANT! Set the runtime to edge: https://vercel.com/docs/functions/edge-functions/edge-runtime -export const runtime = "edge"; - -export async function POST(req: Request): Promise { - // Check if the OPENAI_API_KEY is set, if not return 400 - if (!process.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY === "") { - return new Response( - "Missing OPENAI_API_KEY – make sure to add it to your .env file.", - { - status: 400, - } - ); - } - if ( - process.env.NODE_ENV != "development" && - process.env.KV_REST_API_URL && - process.env.KV_REST_API_TOKEN - ) { - const ip = req.headers.get("x-forwarded-for"); - const ratelimit = new Ratelimit({ - redis: kv, - limiter: Ratelimit.slidingWindow(50, "1 d"), - }); - - const { success, limit, reset, remaining } = await ratelimit.limit( - `novel_ratelimit_${ip}` - ); - - if (!success) { - return new Response("You have reached your request limit for the day.", { - status: 429, - headers: { - "X-RateLimit-Limit": limit.toString(), - "X-RateLimit-Remaining": remaining.toString(), - "X-RateLimit-Reset": reset.toString(), - }, - }); - } - } - - let { prompt } = await req.json(); - - const response = await openai.chat.completions.create({ - model: "gpt-3.5-turbo", - messages: [ - { - role: "system", - content: - "You are an AI writing assistant that continues existing text based on context from prior text. " + - "Give more weight/priority to the later characters than the beginning ones. " + - "Limit your response to no more than 200 characters, but make sure to construct complete sentences.", - // we're disabling markdown for now until we can figure out a way to stream markdown text with proper formatting: https://github.com/steven-tey/novel/discussions/7 - // "Use Markdown formatting when appropriate.", - }, - { - role: "user", - content: prompt, - }, - ], - temperature: 0.7, - top_p: 1, - frequency_penalty: 0, - presence_penalty: 0, - stream: true, - n: 1, - }); - - // Convert the response into a friendly text-stream - const stream = OpenAIStream(response); - - // Respond with the stream - return new StreamingTextResponse(stream); -} diff --git a/emails/DemoTemplate.tsx b/emails/DemoTemplate.tsx index c7b01d2..286c2ae 100644 --- a/emails/DemoTemplate.tsx +++ b/emails/DemoTemplate.tsx @@ -1,3 +1,4 @@ +"use client"; import * as React from "react"; interface EmailTemplateProps { diff --git a/emails/InviteUser.tsx b/emails/InviteUser.tsx index 62a5c20..ff30344 100644 --- a/emails/InviteUser.tsx +++ b/emails/InviteUser.tsx @@ -1,3 +1,4 @@ +"use client"; import { Body, Button, @@ -84,8 +85,6 @@ export const InviteUserEmail = ({