+ <>
+
+
+
+
+
+
+ {visibility === PageVisibilityEnum.Published
+ ? "Published"
+ : visibility === PageVisibilityEnum.Scheduled
+ ? "Scheduled"
+ : "Draft"}
+
+
+
+
+
+
+
+
+ {
+ if (e.key === "Enter") {
+ view?.focus()
+ }
+ }}
+ onChange={(e) => updateValue("title", e.target.value)}
+ className="h-12 ml-1 inline-flex items-center border-none text-3xl font-bold w-full focus:outline-none"
+ placeholder="Title goes here.."
+ />
+
+
+ {previewVisible ? (
+
+ ) : (
+
+ )}
+
+
+
+
- {
- if (e.key === "Enter") {
- view?.focus()
- }
+ ) => {
+ const value = inLocalTimezone(e.target.value).toISOString()
+ updateValue("publishedAt", value)
}}
- onChange={(e) => updateValue("title", e.target.value)}
- className="h-12 ml-1 inline-flex items-center border-none text-3xl font-bold w-full focus:outline-none"
- placeholder="Title goes here.."
+ help={`This ${
+ isPost ? "post" : "page"
+ } will be accesisble from this time`}
/>
-
- {previewVisible ? (
-
- ) : (
-
- )}
+
+ ) =>
+ updateValue("slug", e.target.value)
+ }
+ help={
+ <>
+ {values.slug && (
+ <>
+ This {isPost ? "post" : "page"} will be accessible at{" "}
+
+ {getSiteLink({ subdomain, noProtocol: true })}/
+ {values.slug}
+
+ >
+ )}
+ >
+ }
+ />
+
+ ) => {
+ updateValue("excerpt", e.target.value)
+ }}
+ help="Leave it blank to use auto-generated excerpt"
+ />
+
+ {isPost && page && (
+
+
+ {page?.emailStatus ? (
+
+
+ {page.emailStatus.toLowerCase()}
+
+ ) : (
+
+ )}
+
+ )}
-
-
-
-
+
+
+ {pageId &&
}
+ >
)
}
diff --git a/src/router/page.ts b/src/router/page.ts
index 6855109e..40cbcea0 100644
--- a/src/router/page.ts
+++ b/src/router/page.ts
@@ -15,8 +15,9 @@ export const pageRouter = createRouter()
published: z.boolean().optional(),
publishedAt: z.string().optional(),
excerpt: z.string().optional(),
- isPost: z.boolean(),
+ isPost: z.boolean().optional(),
slug: z.string().optional(),
+ emailSubject: z.string().optional(),
}),
output: z.object({
id: z.string(),
diff --git a/src/router/site.ts b/src/router/site.ts
index 9a0b6eae..afe2bebc 100644
--- a/src/router/site.ts
+++ b/src/router/site.ts
@@ -10,30 +10,12 @@ import {
unsubscribeFromSite,
} from "~/models/site.model"
import {
- createOrUpdatePage,
getPage,
- deletePage,
getPagesBySite,
- notifySubscribersForNewPost,
+ scheduleEmailForPost,
} from "~/models/page.model"
export const siteRouter = createRouter()
- .query("subscribersNotifiedAt", {
- input: z.object({
- pageId: z.string(),
- }),
- output: z
- .date()
- .transform((v) => v.toISOString())
- .nullable(),
- async resolve({ input, ctx }) {
- const page = await getPage(ctx.gate, { page: input.pageId })
- if (!ctx.gate.isOwnerOrAdmin(page.siteId)) {
- throw ctx.gate.permissionError()
- }
- return page.subscribersNotifiedAt
- },
- })
.query("subscription", {
input: z.object({
site: z.string(),
@@ -123,6 +105,9 @@ export const siteRouter = createRouter()
}),
)
.optional(),
+ emailSubject: z.string().nullish(),
+ emailStatus: z.string().nullish(),
+ siteId: z.string(),
}),
async resolve({ input, ctx }) {
const page = await getPage(ctx.gate, input)
@@ -205,13 +190,15 @@ export const siteRouter = createRouter()
await unsubscribeFromSite(ctx.gate, input)
},
})
- .mutation("notifySubscribersForNewPost", {
+ .mutation("scheduleEmailForPost", {
input: z.object({
pageId: z.string(),
+ emailSubject: z.string().optional(),
}),
async resolve({ ctx, input }) {
- await notifySubscribersForNewPost(ctx.gate, {
+ await scheduleEmailForPost(ctx.gate, {
pageId: input.pageId,
+ emailSubject: input.emailSubject,
})
},
})