-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Move integrations to separate page, add testing email API #700
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
Merged
+529
−51
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # VitNode | ||
|
|
||
| - Always write and run unit tests in vitest for all new features and bug fixes. | ||
| - Don't use `React.FC` for defining React components. Instead, use the arrow function syntax. | ||
| - Don't use `any` type in TypeScript and use `unknown` as less as possible. | ||
| - Use `AutoForm` for forms instead of manually creating form components. | ||
| - After create/edit/delete operations, always refresh the data in the table to reflect the changes with notification using toast `sonner`. | ||
| - Use `React.lazy` and `Suspense` for code splitting and lazy loading for content-heavy dialogs like dialogs in forms. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/app/[locale]/admin/(auth)/(plugins)/(vitnode-core)/core/system/integrations/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { getTranslations } from "next-intl/server"; | ||
| import { notFound } from "next/navigation"; | ||
| import React from "react"; | ||
|
|
||
| import { I18nProvider } from "@vitnode/core/components/i18n-provider"; | ||
| import { HeaderContent } from "@vitnode/core/components/ui/header-content"; | ||
| import { checkAdminPermissionApi } from "@vitnode/core/lib/api/get-session-admin-api"; | ||
| import { | ||
| IntegrationsView, | ||
| IntegrationsViewSkeleton, | ||
| } from "@vitnode/core/views/admin/views/core/system/integrations/integrations-view"; | ||
|
|
||
| export const generateMetadata = async () => { | ||
| const t = await getTranslations("admin.system.integrations"); | ||
|
|
||
| return { | ||
| title: t("title"), | ||
| description: t("desc"), | ||
| }; | ||
| }; | ||
|
|
||
| export default async function Page() { | ||
| const [t, canView] = await Promise.all([ | ||
| getTranslations("admin.system.integrations"), | ||
| checkAdminPermissionApi({ module: "system", permission: "can_view" }), | ||
| ]); | ||
|
|
||
| if (!canView) { | ||
| notFound(); | ||
| } | ||
|
|
||
| return ( | ||
| <I18nProvider namespaces="admin.system.integrations"> | ||
| <div className="p-4"> | ||
| <HeaderContent desc={t("desc")} h1={t("title")} /> | ||
|
|
||
| <React.Suspense fallback={<IntegrationsViewSkeleton />}> | ||
| <IntegrationsView /> | ||
| </React.Suspense> | ||
| </div> | ||
| </I18nProvider> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/vitnode/src/api/modules/admin/debug/routes/send-test-email.route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { HTTPException } from "hono/http-exception"; | ||
| import { z } from "zod"; | ||
|
|
||
| import { buildRoute } from "@/api/lib/route"; | ||
| import { CONFIG_PLUGIN } from "@/config"; | ||
| import TestEmailTemplate from "@/emails/test-email"; | ||
|
|
||
| export const zodSendTestEmailSchema = z.object({ | ||
| content: z.string().min(1).max(5000), | ||
| subject: z.string().min(1).max(200), | ||
| to: z.email(), | ||
| }); | ||
|
|
||
| export const sendTestEmailDebugAdminRoute = buildRoute({ | ||
| pluginId: CONFIG_PLUGIN.pluginId, | ||
| adminStaffPermission: { module: "system", permission: "can_send_test_email" }, | ||
| route: { | ||
| method: "post", | ||
| description: | ||
| "Send a test email to verify that the email adapter is configured correctly.", | ||
| path: "/send-test-email", | ||
| request: { | ||
| body: { | ||
| required: true, | ||
| content: { | ||
| "application/json": { | ||
| schema: zodSendTestEmailSchema, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| content: { | ||
| "application/json": { | ||
| schema: z.object({ success: z.boolean() }), | ||
| }, | ||
| }, | ||
| description: "Test email sent", | ||
| }, | ||
| 400: { | ||
| description: "Email adapter not configured", | ||
| }, | ||
| }, | ||
| }, | ||
| handler: async c => { | ||
| // The adapter check gives a clear error instead of the generic 500 the | ||
| // email model would otherwise throw when no provider is configured. | ||
| if (!c.get("core").email?.adapter) { | ||
| throw new HTTPException(400, { | ||
| message: "Email provider not configured", | ||
| }); | ||
| } | ||
|
|
||
| const { to, subject, content } = c.req.valid("json"); | ||
|
|
||
| await c.get("email").send({ | ||
| to, | ||
| locale: "en", | ||
| subject, | ||
| content: props => TestEmailTemplate({ ...props, content }), | ||
| }); | ||
|
|
||
| return c.json({ success: true }); | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Text } from "@react-email/components"; | ||
|
|
||
| import DefaultTemplateEmail, { | ||
| type DefaultTemplateEmailProps, | ||
| } from "./default-template"; | ||
|
|
||
| export default function TestEmailTemplate({ | ||
| content, | ||
| ...props | ||
| }: DefaultTemplateEmailProps & { content: string }) { | ||
| return ( | ||
| <DefaultTemplateEmail {...props}> | ||
| <Text className="whitespace-pre-line">{content}</Text> | ||
| </DefaultTemplateEmail> | ||
| ); | ||
| } | ||
|
|
||
| TestEmailTemplate.PreviewProps = { | ||
| ...DefaultTemplateEmail.PreviewProps, | ||
| content: "This is a test email sent from the VitNode admin panel.", | ||
| } satisfies DefaultTemplateEmailProps & { content: string }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.