feat: Implement company offer submission page and success notification
- Added CompanyOffer component for submitting company offers with validation. - Integrated email sending functionality upon form submission. - Created a success page for company registration confirmation. - Introduced a reusable SuccessNotification component for displaying success messages. - Updated account update functionality with new fields and validation. - Enhanced user experience with back button and logo components. - Added necessary database migrations for account updates.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { MedReportLogo } from '@/components/med-report-title';
|
||||
import { MedReportLogo } from '@/components/med-report-logo';
|
||||
import { ArrowRightIcon } from 'lucide-react';
|
||||
|
||||
import { CtaButton, Hero } from '@kit/ui/marketing';
|
||||
@@ -49,7 +49,7 @@ function MainCallToActionButton() {
|
||||
</CtaButton>
|
||||
|
||||
<CtaButton variant={'link'}>
|
||||
<Link href={'/register-company'}>
|
||||
<Link href={'/company-offer'}>
|
||||
<Trans i18nKey={'account:createCompanyAccount'} />
|
||||
</Link>
|
||||
</CtaButton>
|
||||
|
||||
@@ -4,12 +4,11 @@ import React from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { MedReportLogo } from '@/components/med-report-title';
|
||||
import { MedReportLogo } from '@/components/med-report-logo';
|
||||
import { SubmitButton } from '@/components/ui/submit-button';
|
||||
import { sendCompanyOfferEmail } from '@/lib/services/mailer.service';
|
||||
import { submitCompanyRegistration } from '@/lib/services/register-company.service';
|
||||
import { CompanySubmitData } from '@/lib/types/company';
|
||||
import { companySchema } from '@/lib/validations/companySchema';
|
||||
import { companyOfferSchema } from '@/lib/validations/company-offer.schema';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -19,36 +18,35 @@ import { Input } from '@kit/ui/input';
|
||||
import { Label } from '@kit/ui/label';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
export default function RegisterCompany() {
|
||||
export default function CompanyOffer() {
|
||||
const router = useRouter();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors, isValid, isSubmitting },
|
||||
formState: { isValid, isSubmitting },
|
||||
} = useForm({
|
||||
resolver: zodResolver(companySchema),
|
||||
resolver: zodResolver(companyOfferSchema),
|
||||
mode: 'onChange',
|
||||
});
|
||||
const language = useTranslation().i18n.language;
|
||||
|
||||
async function onSubmit(data: CompanySubmitData) {
|
||||
const onSubmit = async (data: CompanySubmitData) => {
|
||||
const formData = new FormData();
|
||||
Object.entries(data).forEach(([key, value]) => {
|
||||
if (value !== undefined) formData.append(key, value);
|
||||
});
|
||||
|
||||
try {
|
||||
await submitCompanyRegistration(formData);
|
||||
sendCompanyOfferEmail(data, language)
|
||||
.then(() => router.push('/register-company/success'))
|
||||
.then(() => router.push('/company-offer/success'))
|
||||
.catch((error) => alert('error: ' + error));
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof Error) {
|
||||
alert('Server validation error: ' + err.message);
|
||||
console.warn('Server validation error: ' + err.message);
|
||||
}
|
||||
alert('Server validation error');
|
||||
console.warn('Server validation error: ', err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
|
||||
16
app/(public)/company-offer/success/page.tsx
Normal file
16
app/(public)/company-offer/success/page.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import { SuccessNotification } from '@/packages/features/notifications/src/components';
|
||||
|
||||
export default function CompanyRegistrationSuccess() {
|
||||
return (
|
||||
<SuccessNotification
|
||||
titleKey="account:requestCompanyAccount:successTitle"
|
||||
descriptionKey="account:requestCompanyAccount:successDescription"
|
||||
buttonProps={{
|
||||
buttonTitleKey: 'account:requestCompanyAccount:successButton',
|
||||
href: '/',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
|
||||
import { MedReportLogo } from '@/components/med-report-title';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
export default function CompanyRegistrationSuccess() {
|
||||
return (
|
||||
<div className="border-border rounded-3xl border px-16 pt-4 pb-12">
|
||||
<MedReportLogo />
|
||||
<div className="flex flex-col items-center px-4">
|
||||
<Image
|
||||
src="/assets/success.png"
|
||||
alt="Success"
|
||||
className="pt-6 pb-8"
|
||||
width={326}
|
||||
height={195}
|
||||
/>
|
||||
<h1 className="pb-2">
|
||||
<Trans i18nKey="account:requestCompanyAccount:successTitle" />
|
||||
</h1>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
<Trans i18nKey="account:requestCompanyAccount:successDescription" />
|
||||
</p>
|
||||
</div>
|
||||
<Button className="mt-8 w-full">
|
||||
<Link href="/">
|
||||
<Trans i18nKey="account:requestCompanyAccount:successButton" />
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Button } from '@kit/ui/button';
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
|
||||
export default async function SignIn() {
|
||||
return (
|
||||
@@ -15,7 +17,7 @@ export default async function SignIn() {
|
||||
<Link href="/">ID-Kaart</Link>
|
||||
</Button>
|
||||
<Button variant="outline">
|
||||
<Link href="/register-company">Loo ettevõtte konto</Link>
|
||||
<Link href="/company-offer">Loo ettevõtte konto</Link>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
9
app/auth/confirm/layout.tsx
Normal file
9
app/auth/confirm/layout.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
|
||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;
|
||||
}
|
||||
|
||||
export default AuthLayout;
|
||||
9
app/auth/password-reset/layout.tsx
Normal file
9
app/auth/password-reset/layout.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
|
||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;
|
||||
}
|
||||
|
||||
export default AuthLayout;
|
||||
9
app/auth/sign-in/layout.tsx
Normal file
9
app/auth/sign-in/layout.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
|
||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;
|
||||
}
|
||||
|
||||
export default AuthLayout;
|
||||
@@ -1,5 +1,7 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { register } from 'module';
|
||||
|
||||
import { SignInMethodsContainer } from '@kit/auth/sign-in';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Heading } from '@kit/ui/heading';
|
||||
@@ -26,7 +28,8 @@ export const generateMetadata = async () => {
|
||||
};
|
||||
|
||||
async function SignInPage({ searchParams }: SignInPageProps) {
|
||||
const { invite_token: inviteToken, next = '' } = await searchParams;
|
||||
const { invite_token: inviteToken, next = pathsConfig.app.home } =
|
||||
await searchParams;
|
||||
|
||||
const signUpPath =
|
||||
pathsConfig.auth.signUp +
|
||||
@@ -36,6 +39,7 @@ async function SignInPage({ searchParams }: SignInPageProps) {
|
||||
callback: pathsConfig.auth.callback,
|
||||
returnPath: next ?? pathsConfig.app.home,
|
||||
joinTeam: pathsConfig.app.joinTeam,
|
||||
updateAccount: pathsConfig.auth.updateAccount,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
9
app/auth/sign-up/layout.tsx
Normal file
9
app/auth/sign-up/layout.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
|
||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;
|
||||
}
|
||||
|
||||
export default AuthLayout;
|
||||
@@ -27,6 +27,7 @@ interface Props {
|
||||
const paths = {
|
||||
callback: pathsConfig.auth.callback,
|
||||
appHome: pathsConfig.app.home,
|
||||
updateAccount: pathsConfig.auth.updateAccount,
|
||||
};
|
||||
|
||||
async function SignUpPage({ searchParams }: Props) {
|
||||
|
||||
11
app/auth/update-account/layout.tsx
Normal file
11
app/auth/update-account/layout.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
async function SiteLayout(props: React.PropsWithChildren) {
|
||||
return (
|
||||
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default withI18n(SiteLayout);
|
||||
43
app/auth/update-account/page.tsx
Normal file
43
app/auth/update-account/page.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { BackButton } from '@/components/back-button';
|
||||
import { MedReportLogo } from '@/components/med-report-logo';
|
||||
import pathsConfig from '@/config/paths.config';
|
||||
import { signOutAction } from '@/lib/actions/sign-out';
|
||||
import { UpdateAccountForm } from '@/packages/features/auth/src/components/update-account-form';
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
async function UpdateAccount() {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await client.auth.getUser();
|
||||
|
||||
if (!user) {
|
||||
redirect(pathsConfig.auth.signIn);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
|
||||
<div className="relative flex w-1/2 min-w-md flex-col px-12 pt-7 pb-22 text-center">
|
||||
<BackButton onBack={signOutAction} />
|
||||
<MedReportLogo />
|
||||
<h1 className="pt-8">
|
||||
<Trans i18nKey={'account:updateAccount:title'} />
|
||||
</h1>
|
||||
<p className="text-muted-foreground pt-1 text-sm">
|
||||
<Trans i18nKey={'account:updateAccount:description'} />
|
||||
</p>
|
||||
<UpdateAccountForm user={user} />
|
||||
</div>
|
||||
<div className="w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default withI18n(UpdateAccount);
|
||||
17
app/auth/update-account/success/page.tsx
Normal file
17
app/auth/update-account/success/page.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
||||
|
||||
import { UpdateAccountSuccessNotification } from '@kit/notifications/components';
|
||||
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
|
||||
async function UpdateAccountSuccess() {
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await client.auth.getUser();
|
||||
|
||||
return <UpdateAccountSuccessNotification userId={user?.id} />;
|
||||
}
|
||||
|
||||
export default withI18n(UpdateAccountSuccess);
|
||||
9
app/auth/verify/layout.tsx
Normal file
9
app/auth/verify/layout.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
|
||||
function AuthLayout({ children }: React.PropsWithChildren) {
|
||||
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;
|
||||
}
|
||||
|
||||
export default AuthLayout;
|
||||
@@ -2,6 +2,7 @@ import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@/packages/supabase/src/database.types';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createAccountsApi } from '@kit/accounts/api';
|
||||
@@ -13,7 +14,6 @@ import { requireUser } from '@kit/supabase/require-user';
|
||||
import appConfig from '~/config/app.config';
|
||||
import billingConfig from '~/config/billing.config';
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
import { Database } from '~/lib/database.types';
|
||||
|
||||
import { PersonalAccountCheckoutSchema } from '../schema/personal-account-checkout.schema';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@/packages/supabase/src/database.types';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { LineItemSchema } from '@kit/billing';
|
||||
@@ -14,7 +15,6 @@ import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
import appConfig from '~/config/app.config';
|
||||
import billingConfig from '~/config/billing.config';
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
import { Database } from '~/lib/database.types';
|
||||
|
||||
import { TeamCheckoutSchema } from '../schema/team-billing.schema';
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import 'server-only';
|
||||
|
||||
import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { Database } from '@/packages/supabase/src/database.types';
|
||||
|
||||
import { loadTeamWorkspace } from '~/home/[account]/_lib/server/team-account-workspace.loader';
|
||||
import { Database } from '~/lib/database.types';
|
||||
|
||||
/**
|
||||
* Load data for the members page
|
||||
|
||||
Reference in New Issue
Block a user