Skip to content

Commit

Permalink
Add Superforms namespace and Message type
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspresume committed Mar 7, 2024
1 parent d8016b7 commit a23c97c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for information about these interfaces

import type { MetaTagsProps } from 'svelte-meta-tags';

declare global {
namespace App {
// interface Error {}
Expand All @@ -13,6 +14,13 @@ declare global {
}
// interface PageState {}
// interface Platform {}

namespace Superforms {
type Message = {
alertType: 'success' | 'error' | 'warning' | 'info';
alertText: string;
};
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export type AlertMessageType = {
alertType: 'success' | 'error' | 'warning' | 'info';
alertText: string;
};

export type EnterKeyHintType =
| 'search'
| 'enter'
Expand Down
24 changes: 3 additions & 21 deletions src/routes/sendFeedbackToEmail/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ import type { Actions } from './$types';
import nodemailer from 'nodemailer';

import { zod } from 'sveltekit-superforms/adapters';
import {
message,
superValidate,
type Infer,
type SuperValidated
} from 'sveltekit-superforms/server';

import type { AlertMessageType } from '$lib/types';
import { message, superValidate } from 'sveltekit-superforms/server';

import { logError, sanitizeContent } from '$lib/utils';

import {
FeedbackValidationSchema,
type FeedbackValidationSchemaType
} from '$validations/feedbackValidationSchema';
import { FeedbackValidationSchema } from '$validations/feedbackValidationSchema';

/**
* Creates a nodemailer Transporter instance
Expand Down Expand Up @@ -46,17 +36,9 @@ async function sendEmail(mailOptions: object) {
return emailTransporter.sendMail(mailOptions);
}

type FeedbackFormValidateType = SuperValidated<
Infer<FeedbackValidationSchemaType>,
AlertMessageType
>;

export const actions: Actions = {
default: async ({ request }) => {
const feedbackForm: FeedbackFormValidateType = await superValidate(
request,
zod(FeedbackValidationSchema)
);
const feedbackForm = await superValidate(request, zod(FeedbackValidationSchema));

if (!feedbackForm.valid) {
return message(feedbackForm, {
Expand Down

0 comments on commit a23c97c

Please sign in to comment.