-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inv-126 : 타이틀, 내용 업데이트 쿼리 #64
Changes from 6 commits
190cf6e
80d687c
7b6b807
d6a2470
129d5f0
1415fbe
eae2757
08338c5
1426349
25cace2
f1d5f8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,23 @@ | ||
import Editor from "~/components/editor"; | ||
import { getInvitationByEventUrl } from "~/lib/db/schema/invitations.query"; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: { subdomain: string }; | ||
}) { | ||
const subDomain = params.subdomain; | ||
const invitation = await getInvitationByEventUrl(subDomain as string); | ||
|
||
export default async function Page() { | ||
return ( | ||
<Editor | ||
editorConfig={{ backLink: "/pg" }} | ||
editorData={[ | ||
{ | ||
id: "__body", | ||
type: "__body", | ||
name: "Body", | ||
styles: {}, | ||
content: [ | ||
{ | ||
id: "container", | ||
name: "Container", | ||
type: "container", | ||
styles: { | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
gap: 10, | ||
paddingTop: 10, | ||
paddingRight: 10, | ||
paddingBottom: 10, | ||
paddingLeft: 10, | ||
width: "100%", | ||
height: "auto", | ||
}, | ||
content: [ | ||
{ | ||
id: "text", | ||
name: "Text", | ||
type: "text", | ||
styles: { | ||
textAlign: "left", | ||
}, | ||
content: { | ||
innerText: "Hello World", | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]} | ||
editorConfig={{ | ||
backLink: "/pg", | ||
invitationId: invitation.id, | ||
invitationTitle: invitation.title, | ||
invitationSubdomain: invitation.eventUrl, | ||
}} | ||
editorData={invitation.customFields} | ||
/> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Script from "next/script"; | ||
import { env } from "~/lib/env"; | ||
|
||
export default function KakaoMapScriptLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<Script | ||
strategy="beforeInteractive" | ||
type="text/javascript" | ||
src={`${env.DAUMCDN_POSTOCDE_URL}`} | ||
/> | ||
<Script | ||
strategy="beforeInteractive" | ||
type="text/javascript" | ||
src={`${env.KAKAO_MAP_BASE_URL}?appkey=${env.KAKAO_MAP_API_KEY}&libraries=services&autoload=false`} | ||
/> | ||
{children} | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
"use client"; | ||
|
||
import { useMutation } from "@tanstack/react-query"; | ||
import { debounce, delay, random } from "es-toolkit"; | ||
import { debounce, delay } from "es-toolkit"; | ||
import { CheckIcon, LoaderIcon, XIcon } from "lucide-react"; | ||
import { useRef } from "react"; | ||
import { toast } from "sonner"; | ||
import { useEditor } from "~/components/editor/provider"; | ||
import { updateInvitation } from "~/lib/db/schema/invitations.query"; | ||
import { cn } from "~/lib/utils"; | ||
|
||
export default function TitleInput() { | ||
|
@@ -45,11 +46,11 @@ export default function TitleInput() { | |
if (signal.aborted) { | ||
return; | ||
} | ||
|
||
if (random(0, 1) > 0.5) { | ||
throw new Error("Failed to update title"); | ||
} | ||
|
||
editor.config.invitationTitle = value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
await updateInvitation({ | ||
id: editor.config.invitationSubdomain, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거 |
||
title: value, | ||
}); | ||
delayMutation.mutate(); | ||
}, | ||
onError: () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import { count, eq } from "drizzle-orm"; | ||
import { nanoid } from "nanoid"; | ||
import { getAuth } from "~/lib/auth/utils"; | ||
import { db } from "~/lib/db"; | ||
import { | ||
invitations, | ||
|
@@ -11,7 +12,7 @@ import { | |
|
||
type CreateInvitationParams = Omit< | ||
InvitationInsert, | ||
"id" | "eventUrl" | "createdAt" | "updatedAt" | ||
"id" | "userId" | "eventUrl" | "createdAt" | "updatedAt" | ||
>; | ||
|
||
type UpdateInvitationParams = { | ||
|
@@ -41,27 +42,31 @@ export async function getInvitationByEventUrl(eventUrl: string) { | |
return responses[0]; | ||
} | ||
|
||
export async function getInvitationsByUserId( | ||
userId: Invitation["userId"], | ||
): Promise<Invitation[]> { | ||
export async function getInvitationsByUserId(): Promise<Invitation[]> { | ||
const sessionId = await getAuth(); | ||
const sessionUserId = sessionId.session.userId; | ||
|
||
return await db | ||
.select() | ||
.from(invitations) | ||
.where(eq(invitations.userId, userId)); | ||
.where(eq(invitations.userId, sessionUserId)); | ||
} | ||
|
||
export async function createInvitation( | ||
params: CreateInvitationParams, | ||
): Promise<InvitationInsert> { | ||
const id = nanoid(); | ||
const currentTimestamp = new Date(); | ||
const sessionId = await getAuth(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const sessionUserId = sessionId.session.userId; | ||
|
||
try { | ||
const res = await db | ||
.insert(invitations) | ||
.values({ | ||
...params, | ||
id, | ||
userId: sessionUserId, | ||
eventUrl: id, | ||
createdAt: currentTimestamp, | ||
updatedAt: currentTimestamp, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 content는 로깅을 위해서 stringify한 것이기에
editor.data
를customFields
로 요청해주세요.