-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve add target placeholder page (#29)
* fixed button * Changed add-target page design * Redesigned page * Insert waiting list item to db * send emails * Changed validation to zod * fixed validation schemas * add disabled state * Fixed type * Updated pnpm version in github action * Small improvements * Fixed comments
- Loading branch information
1 parent
c9c83e7
commit 9796b27
Showing
17 changed files
with
247 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,31 +1,40 @@ | ||
import { Head, Layout } from '@/components'; | ||
import InputField from '@/components/InputField'; | ||
import { Button } from '@/components/ui/Button'; | ||
import { GradientContainer } from '@/ui/GradientContainer'; | ||
import Spacer from '@/ui/Spacer'; | ||
import { trpc } from '@/utils/trpc'; | ||
import { Form, Formik } from 'formik'; | ||
import { useRouter } from 'next/router'; | ||
import { MdNotificationsNone } from 'react-icons/md'; | ||
import z from 'zod'; | ||
import { toFormikValidationSchema } from 'zod-formik-adapter'; | ||
import type { NextPageWithLayout } from './_app'; | ||
|
||
const AddTarget: NextPageWithLayout = () => { | ||
return ( | ||
<> | ||
<main className='mx-auto max-w-screen-sm px-2'> | ||
<Head title={'Додати людину'} /> | ||
<Spacer className='h-12' /> | ||
<div className='mx-auto max-w-screen-sm px-2 '> | ||
<GradientContainer> | ||
<div className=' px-4 py-5 text-sm font-light'> | ||
<span className='font-normal'> | ||
На жаль, ця частина ще не готова | ||
</span> | ||
, але Ви можете відправити нам інформацію на пошту{' '} | ||
<a | ||
className='font-mono text-blue-600' | ||
href='mailto:[email protected]' | ||
> | ||
[email protected] | ||
</a>{' '} | ||
🙂 | ||
</div> | ||
</GradientContainer> | ||
<div className='h-7 md:h-12' /> | ||
<div className='font-light'> | ||
<span className='font-normal'>На жаль, ця частина ще не готова</span>, | ||
але Ви можете відправити нам інформацію на пошту{' '} | ||
<a | ||
className='font-mono text-blue-600' | ||
href='mailto:[email protected]' | ||
> | ||
[email protected] | ||
</a>{' '} | ||
🙂 | ||
<br /> | ||
<br /> | ||
Або... | ||
<br /> | ||
<br /> | ||
</div> | ||
</> | ||
<div className='h-2' /> | ||
<NotifyUser /> | ||
</main> | ||
); | ||
}; | ||
|
||
|
@@ -34,3 +43,62 @@ AddTarget.getLayout = (page) => { | |
}; | ||
|
||
export default AddTarget; | ||
|
||
const validationSchema = z.object({ | ||
email: z | ||
.string({ required_error: 'Уведіть email' }) | ||
.email('Невалідний email'), | ||
}); | ||
|
||
type EmailForm = z.infer<typeof validationSchema>; | ||
|
||
function NotifyUser() { | ||
const router = useRouter(); | ||
const mutation = trpc.waitingList.add.useMutation(); | ||
|
||
function handleSubmit(values: EmailForm) { | ||
mutation.mutate(values, { | ||
onSuccess() { | ||
alert('Дякуємо! Ми повідомимо Вас, коли цей функціонал буде готовий.'); | ||
router.push('/'); | ||
}, | ||
onError() { | ||
alert('Щось пішло не так, спробуйте, будь ласка, ще раз.'); | ||
}, | ||
}); | ||
} | ||
|
||
return ( | ||
<Formik | ||
initialValues={{ email: '' }} | ||
onSubmit={handleSubmit} | ||
validationSchema={toFormikValidationSchema(validationSchema)} | ||
> | ||
{({}) => ( | ||
<Form> | ||
<GradientContainer className='px-4 md:px-10'> | ||
<div className='h-6' /> | ||
<div className='flex items-center justify-center'> | ||
<MdNotificationsNone size={50} /> | ||
</div> | ||
<div className='h-4' /> | ||
<div className='text-center font-light'> | ||
Ми повідомимо Вас, коли цей функціонал буде додано | ||
</div> | ||
<div className='h-4' /> | ||
<InputField name='email' type='email' placeholderLabel='Email' /> | ||
<div className='h-6' /> | ||
<Button | ||
type='submit' | ||
className='w-full rounded-full py-6' | ||
disabled={mutation.isLoading} | ||
> | ||
Повідомте мене | ||
</Button> | ||
<div className='h-8' /> | ||
</GradientContainer> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
} |
This file contains 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,5 @@ | ||
import { z } from 'zod'; | ||
|
||
export const addToWaitListSchema = z.object({ email: z.string().email() }); | ||
|
||
export type AddToWaitListSchema = z.infer<typeof addToWaitListSchema>; |
This file contains 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,37 @@ | ||
import nodemailer from 'nodemailer'; | ||
import type Mail from 'nodemailer/lib/mailer'; | ||
import type SMTPTransport from 'nodemailer/lib/smtp-transport'; | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: process.env.NODEMAILER_EMAIL, | ||
pass: process.env.NODEMAILER_PSW, | ||
}, | ||
}); | ||
|
||
export interface Message extends Omit<Mail.Options, 'from' | 'bcc'> {} | ||
|
||
export function sendMail( | ||
message: Message, | ||
): Promise<SMTPTransport.SentMessageInfo | Error> { | ||
const bcc = process.env.NODEMAILER_EMAIL; | ||
|
||
const mail: Mail.Options = { | ||
...message, | ||
from: process.env.NODEMAILER_EMAIL, | ||
bcc: bcc, | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
transporter.sendMail(mail, (err, info) => { | ||
if (err) { | ||
console.log(err); | ||
reject(err); | ||
} else { | ||
console.log(info); | ||
resolve(info); | ||
} | ||
}); | ||
}); | ||
} |
This file contains 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 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,29 @@ | ||
import { sendMail, type Message } from '@/server/sendMail'; | ||
import { publicProcedure, router } from '../trpc'; | ||
import { addToWaitListSchema } from '@/server/schema/wait-list.schema'; | ||
|
||
export const waitingListRouter = router({ | ||
add: publicProcedure | ||
.input(addToWaitListSchema) | ||
.mutation(async ({ ctx, input }) => { | ||
await ctx.prisma.waitingList.upsert({ | ||
where: { email: input.email }, | ||
update: { | ||
submitCount: { | ||
increment: 1, | ||
}, | ||
}, | ||
create: { | ||
email: input.email, | ||
}, | ||
}); | ||
|
||
const message: Message = { | ||
to: input.email, | ||
subject: 'Вітаємо! Вас додано до списку очікування | 🇺🇦 UA validator', | ||
text: 'Ми повідомимо Ваc, коли буде можливо додавати людей до списку.\n\n🇺🇦 UA validator', | ||
}; | ||
|
||
await sendMail(message); | ||
}), | ||
}); |
Oops, something went wrong.
9796b27
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.
Successfully deployed to the following URLs:
ukrainian-validator – ./
ukrainian-validator-git-main-sadxprod.vercel.app
ukrainian-validator.vercel.app
uavalidator.com
ukrainian-validator-sadxprod.vercel.app
www.uavalidator.com