feat: manually send email for new posts

This commit is contained in:
EGOIST
2022-06-07 20:54:50 +08:00
parent f2a6492ceb
commit 26a93cf45b
17 changed files with 424 additions and 221 deletions
+57
View File
@@ -0,0 +1,57 @@
import { PageEmailStatus } from "@prisma/client"
import { useForm } from "react-hook-form"
import toast from "react-hot-toast"
import { useStore } from "~/lib/store"
import { trpc } from "~/lib/trpc"
import { Button } from "../ui/Button"
import { Input } from "../ui/Input"
import { Modal } from "../ui/Modal"
export const EmailPostModal: React.FC<{
pageId: string
}> = ({ pageId }) => {
const [open, setOpen] = useStore((store) => [
store.emailPostModalOpened,
store.setEmailPostModalOpened,
])
const { handleSubmit, register } = useForm({
defaultValues: {
subject: "",
},
})
const scheduleEmailForPost = trpc.useMutation("site.scheduleEmailForPost")
const onSubmit = handleSubmit(async (values) => {
await scheduleEmailForPost.mutateAsync({
pageId,
emailSubject: values.subject,
})
toast.success("Scheduled!")
setOpen(false)
})
return (
<Modal title="Email Post" open={open} setOpen={setOpen}>
{
<form onSubmit={onSubmit}>
<div className="p-5">
<Input
label="Email subject"
id="subject"
help="Defaults to post title"
isBlock
{...register("subject")}
/>
</div>
<div className="p-5 border-t">
<Button type="submit" isLoading={scheduleEmailForPost.isLoading}>
<span className="i-mdi:email-send text-xl mr-1"></span>
<span>Send Email</span>
</Button>
</div>
</form>
}
</Modal>
)
}
-1
View File
@@ -1,6 +1,5 @@
import { Button } from "~/components/ui/Button"
import { useStore } from "~/lib/store"
import { Dialog } from "@headlessui/react"
import { trpc } from "~/lib/trpc"
import { useForm } from "react-hook-form"
import { Modal } from "../ui/Modal"
+4 -2
View File
@@ -126,8 +126,10 @@ export const useEditor = ({
return {
view,
editorRef(node: HTMLDivElement) {
setNode(node)
editorRef(newNode: HTMLDivElement) {
if (!newNode) return
if (node && newNode.isEqualNode(node)) return
setNode(newNode)
},
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({
const active = isPreviewModeCommand && previewVisible
const disabled = !isPreviewModeCommand && previewVisible
return (
<Tooltip label={label} placement="bottom">
<Tooltip key={name} label={label} placement="bottom">
<button
key={name}
type="button"
+10
View File
@@ -0,0 +1,10 @@
export const FieldLabel: React.FC<{ id?: string; label: string }> = ({
id,
label,
}) => {
return (
<label className="form-label" htmlFor={id}>
{label}
</label>
)
}
+6 -9
View File
@@ -1,5 +1,6 @@
import clsx from "clsx"
import { forwardRef } from "react"
import { FieldLabel } from "./FieldLabel"
type InputProps<TMultiline extends boolean> = {
label?: string
@@ -11,7 +12,7 @@ type InputProps<TMultiline extends boolean> = {
} & React.ComponentPropsWithRef<TMultiline extends true ? "textarea" : "input">
export const Input = forwardRef(function Input<
TMutliline extends boolean = false
TMutliline extends boolean = false,
>(
{
label,
@@ -25,18 +26,14 @@ export const Input = forwardRef(function Input<
}: InputProps<TMutliline>,
ref: TMutliline extends true
? React.ForwardedRef<HTMLTextAreaElement>
: React.ForwardedRef<HTMLInputElement>
: React.ForwardedRef<HTMLInputElement>,
) {
const hasAddon = !!addon
const Component = (multiline ? "textarea" : "input") as any
return (
<div>
{label && (
<label className="form-label" htmlFor={inputProps.id}>
{label}
</label>
)}
{label && <FieldLabel label={label} id={inputProps.id} />}
<div className="flex items-center">
<Component
{...inputProps}
@@ -45,7 +42,7 @@ export const Input = forwardRef(function Input<
"input",
hasAddon && `has-addon`,
isBlock && `is-block`,
className
className,
)}
/>
{addon && (
@@ -61,5 +58,5 @@ export const Input = forwardRef(function Input<
</div>
)
}) as <TMultiline extends boolean = false>(
props: InputProps<TMultiline>
props: InputProps<TMultiline>,
) => JSX.Element