feat: enable TLS for email and improve loading state handling in CompanyOfferForm

This commit is contained in:
Danel Kungla
2025-08-07 15:10:59 +03:00
parent 09155ae110
commit 2850478443
2 changed files with 18 additions and 4 deletions

2
.env
View File

@@ -50,7 +50,7 @@ EMAIL_USER= # 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_PORT=1025 # or 465 for SSL
EMAIL_TLS=false
EMAIL_TLS=true
NODE_TLS_REJECT_UNAUTHORIZED=0
# NEXTJS

View File

@@ -1,5 +1,7 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { SubmitButton } from '@/components/ui/submit-button';
@@ -13,9 +15,11 @@ import { useTranslation } from 'react-i18next';
import { FormItem } from '@kit/ui/form';
import { Input } from '@kit/ui/input';
import { Label } from '@kit/ui/label';
import { Spinner } from '@kit/ui/spinner';
import { Trans } from '@kit/ui/trans';
const CompanyOfferForm = () => {
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const language = useTranslation().i18n.language;
const {
@@ -28,6 +32,7 @@ const CompanyOfferForm = () => {
});
const onSubmit = async (data: CompanySubmitData) => {
setIsLoading(true);
const formData = new FormData();
Object.entries(data).forEach(([key, value]) => {
if (value !== undefined) formData.append(key, value);
@@ -36,8 +41,13 @@ const CompanyOfferForm = () => {
try {
sendCompanyOfferEmail(data, language)
.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) {
setIsLoading(false);
if (err instanceof Error) {
console.warn('Server validation error: ' + err.message);
}
@@ -76,11 +86,15 @@ const CompanyOfferForm = () => {
<Input type="tel" {...register('phone')} />
</FormItem>
<SubmitButton
disabled={!isValid || isSubmitting}
disabled={isLoading || !isValid || isSubmitting}
pendingText="Saatmine..."
type="submit"
>
<Trans i18nKey={'account:requestCompanyAccount:button'} />
{isLoading ? (
<Spinner />
) : (
<Trans i18nKey={'account:requestCompanyAccount:button'} />
)}
</SubmitButton>
</form>
);