feat: enable TLS for email and improve loading state handling in CompanyOfferForm
This commit is contained in:
2
.env
2
.env
@@ -50,7 +50,7 @@ EMAIL_USER= # refer to your email provider's documentation
|
|||||||
EMAIL_PASSWORD= # refer to your email provider's documentation
|
EMAIL_PASSWORD= # refer to your email provider's documentation
|
||||||
EMAIL_HOST=localhost # refer to your email provider's documentation
|
EMAIL_HOST=localhost # refer to your email provider's documentation
|
||||||
EMAIL_PORT=1025 # or 465 for SSL
|
EMAIL_PORT=1025 # or 465 for SSL
|
||||||
EMAIL_TLS=false
|
EMAIL_TLS=true
|
||||||
NODE_TLS_REJECT_UNAUTHORIZED=0
|
NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||||
|
|
||||||
# NEXTJS
|
# NEXTJS
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { SubmitButton } from '@/components/ui/submit-button';
|
import { SubmitButton } from '@/components/ui/submit-button';
|
||||||
@@ -13,9 +15,11 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { FormItem } from '@kit/ui/form';
|
import { FormItem } from '@kit/ui/form';
|
||||||
import { Input } from '@kit/ui/input';
|
import { Input } from '@kit/ui/input';
|
||||||
import { Label } from '@kit/ui/label';
|
import { Label } from '@kit/ui/label';
|
||||||
|
import { Spinner } from '@kit/ui/spinner';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
|
||||||
const CompanyOfferForm = () => {
|
const CompanyOfferForm = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const language = useTranslation().i18n.language;
|
const language = useTranslation().i18n.language;
|
||||||
const {
|
const {
|
||||||
@@ -28,6 +32,7 @@ const CompanyOfferForm = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = async (data: CompanySubmitData) => {
|
const onSubmit = async (data: CompanySubmitData) => {
|
||||||
|
setIsLoading(true);
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
Object.entries(data).forEach(([key, value]) => {
|
||||||
if (value !== undefined) formData.append(key, value);
|
if (value !== undefined) formData.append(key, value);
|
||||||
@@ -36,8 +41,13 @@ const CompanyOfferForm = () => {
|
|||||||
try {
|
try {
|
||||||
sendCompanyOfferEmail(data, language)
|
sendCompanyOfferEmail(data, language)
|
||||||
.then(() => router.push('/company-offer/success'))
|
.then(() => router.push('/company-offer/success'))
|
||||||
.catch((error) => alert('error: ' + error));
|
.catch((error) => {
|
||||||
|
setIsLoading(false);
|
||||||
|
alert('Could not send email at this time');
|
||||||
|
console.warn('error: ' + error);
|
||||||
|
});
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
setIsLoading(false);
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
console.warn('Server validation error: ' + err.message);
|
console.warn('Server validation error: ' + err.message);
|
||||||
}
|
}
|
||||||
@@ -76,11 +86,15 @@ const CompanyOfferForm = () => {
|
|||||||
<Input type="tel" {...register('phone')} />
|
<Input type="tel" {...register('phone')} />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<SubmitButton
|
<SubmitButton
|
||||||
disabled={!isValid || isSubmitting}
|
disabled={isLoading || !isValid || isSubmitting}
|
||||||
pendingText="Saatmine..."
|
pendingText="Saatmine..."
|
||||||
type="submit"
|
type="submit"
|
||||||
>
|
>
|
||||||
<Trans i18nKey={'account:requestCompanyAccount:button'} />
|
{isLoading ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<Trans i18nKey={'account:requestCompanyAccount:button'} />
|
||||||
|
)}
|
||||||
</SubmitButton>
|
</SubmitButton>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user