Skip to content

Commit

Permalink
Merge pull request #111 from SergeWilfried/zodi18n
Browse files Browse the repository at this point in the history
Zodi18n
  • Loading branch information
SergeWilfried authored Feb 25, 2024
2 parents 9bbbb61 + fb370a6 commit 052b851
Show file tree
Hide file tree
Showing 66 changed files with 286 additions and 119 deletions.
2 changes: 1 addition & 1 deletion apps/marketing/src/api/claim-plan/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from '@documenso/lib/i18n/settings';

export const ZClaimPlanRequestSchema = z
.object({
Expand Down
4 changes: 4 additions & 0 deletions apps/marketing/src/app/(marketing)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default async function BlogPage() {
const { t } = await createTranslation('marketing');


export default async function BlogPage() {
const { t } = await createTranslation('marketing');


const blogPosts = allBlogPosts.sort((a, b) => {
const dateA = new Date(a.date);
const dateB = new Date(b.date);
Expand Down
2 changes: 1 addition & 1 deletion apps/marketing/src/app/(marketing)/open/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from 'next';

import { z } from 'zod';
import { z } from '@documenso/lib/i18n/settings';

import { getUserMonthlyGrowth } from '@documenso/lib/server-only/user/get-user-monthly-growth';

Expand Down
2 changes: 1 addition & 1 deletion apps/marketing/src/app/(marketing)/oss-friends/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Metadata } from 'next';
import Image from 'next/image';

import { z } from 'zod';
import { z } from '@documenso/lib/i18n/settings';

import backgroundPattern from '@documenso/assets/images/background-pattern.png';

Expand Down
2 changes: 1 addition & 1 deletion apps/marketing/src/app/(marketing)/oss-friends/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z } from '@documenso/lib/i18n/settings';

export const ZOSSFriendsSchema = z.array(
z.object({
Expand Down
4 changes: 2 additions & 2 deletions apps/marketing/src/app/(marketing)/pricing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export default async function PricingPage() {

<div className="mt-4 flex justify-center">
<Button variant="outline" size="lg" className="rounded-full hover:cursor-pointer" asChild>
<Link href="https://github.com/documenso/documenso" target="_blank">
{t('get-started')}

<Link href="https://github.com/documenso/documenso" target="_blank" rel="noreferrer">
{t('get-started')}
</Link>
</Button>
</div>
Expand Down
5 changes: 2 additions & 3 deletions apps/marketing/src/components/(marketing)/pricing-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export const PricingTable = ({ className, ...props }: PricingTableProps) => {
</p>

<Button className="mt-6 rounded-full text-base" asChild>
<Link href={`${NEXT_PUBLIC_WEBAPP_URL()}/signup`}>{t('signup-now')}</Link>

<Link target="_blank" href={`${NEXT_PUBLIC_WEBAPP_URL()}/signup`}>{t('signup-now')}</Link>
</Button>

<div className="mt-8 flex w-full flex-col divide-y">
Expand All @@ -136,8 +135,8 @@ export const PricingTable = ({ className, ...props }: PricingTableProps) => {
<strong>
{' '}
<a href="https://documenso.com/blog/early-adopters" rel="noreferrer" target="_blank">
{t('includes-all-upcoming-features')}

{t('includes-all-upcoming-features')}
</a>
</strong>
</p>
Expand Down
22 changes: 15 additions & 7 deletions apps/marketing/src/components/(marketing)/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { Loader } from 'lucide-react';
import { usePlausible } from 'next-plausible';
import { env } from 'next-runtime-env';
import { Controller, useForm } from 'react-hook-form';
import { z } from 'zod';
import { z } from '@documenso/lib/i18n/settings';

import { useTranslation } from '@documenso/lib/i18n/client';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
import { Card, CardContent } from '@documenso/ui/primitives/card';
Expand All @@ -33,8 +34,10 @@ import { FormErrorMessage } from '../form/form-error-message';

const ZWidgetFormSchema = z
.object({
email: z.string().email({ message: 'Please enter a valid email address.' }),
name: z.string().trim().min(3, { message: 'Please enter a valid name.' }),
email: z.string().email({ message: 'please-enter-a-valid-email-address'}),
name: z
.string()
.trim().min(3, { message: 'please-enter-a-valid-name' }),
})
.and(
z.union([
Expand Down Expand Up @@ -149,7 +152,7 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
const planId = env('NEXT_PUBLIC_STRIPE_COMMUNITY_PLAN_MONTHLY_PRICE_ID');

if (!planId) {
throw new Error('No plan ID found.');
throw new Error(t('no-plan-id-found'));
}

const claimPlanInput = signatureDataUrl
Expand Down Expand Up @@ -315,10 +318,13 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {

<div className="flex items-center justify-between">
<p className="text-muted-foreground text-xs">
{isValid ? t('ready-for-signing') : `${stepsRemaining} step(s) until signed`}
{isValid ? t('ready-for-signing') : t('steps-remaining-step-s-until-signed-singular', {count: steps})}
</p>

<p className="text-muted-foreground block text-xs md:hidden">
{t('minimise-contract')}
</p>

<p className="text-muted-foreground block text-xs md:hidden">{t('minimise-contract')}</p>
</div>

<div className="bg-background relative mt-2.5 h-[2px] w-full">
Expand Down Expand Up @@ -400,7 +406,9 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
<DialogDescription>
{t('by-signing-you-signal-your-support-of-montampons-mission-in-a')} <br></br>
<strong>{t('non-legally-binding-but-heartfelt-way')}</strong>. <br></br>
<br></br>{t('you-also-unlock-the-option')}
<br></br>
{t('you-also-unlock-the-option')}

</DialogDescription>

<SignaturePad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { useRouter } from 'next/navigation';

import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { AppError } from '@documenso/lib/errors/app-error';
import { z } from '@documenso/lib/i18n/settings';
import { trpc } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
import {
Expand All @@ -31,6 +31,7 @@ import {
import { Input } from '@documenso/ui/primitives/input';
import type { Toast } from '@documenso/ui/primitives/use-toast';
import { useToast } from '@documenso/ui/primitives/use-toast';
import { useTranslation } from '@documenso/lib/i18n/client';

export type DeleteTeamDialogProps = {
teamId: number;
Expand All @@ -41,14 +42,14 @@ export type DeleteTeamDialogProps = {
export const DeleteTeamDialog = ({ trigger, teamId, teamName }: DeleteTeamDialogProps) => {
const router = useRouter();
const [open, setOpen] = useState(false);

const { t } = useTranslation('web');
const { toast } = useToast();

const deleteMessage = `delete ${teamName}`;
const deleteMessage = t(`delete-message`, {teamName});

const ZDeleteTeamFormSchema = z.object({
teamName: z.literal(deleteMessage, {
errorMap: () => ({ message: `You must enter '${deleteMessage}' to proceed` }),
errorMap: () => ({ message: t(`you-must-enter`, {deleteMessage})}),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { zodResolver } from '@hookform/resolvers/zod';
import type * as DialogPrimitive from '@radix-ui/react-dialog';
import { Mail, PlusCircle, Trash } from 'lucide-react';
import { useFieldArray, useForm } from 'react-hook-form';
import { z } from 'zod';

import { TEAM_MEMBER_ROLE_HIERARCHY, TEAM_MEMBER_ROLE_MAP } from '@documenso/lib/constants/teams';
import { z } from '@documenso/lib/i18n/settings';
import { TeamMemberRole } from '@documenso/prisma/client';
import { trpc } from '@documenso/trpc/react';
import { ZCreateTeamMemberInvitesMutationSchema } from '@documenso/trpc/server/team-router/schema';
Expand Down Expand Up @@ -40,6 +40,7 @@ import {
SelectValue,
} from '@documenso/ui/primitives/select';
import { useToast } from '@documenso/ui/primitives/use-toast';
import { useTranslation } from '@documenso/lib/i18n/client';

export type InviteTeamMembersDialogProps = {
currentUserTeamRole: TeamMemberRole;
Expand All @@ -58,7 +59,7 @@ const ZInviteTeamMembersFormSchema = z
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Members must have unique emails', path: ['members__root'] },
{ message: 'members-must-have-unique-emails', path: ['members__root'] },
);

type TInviteTeamMembersFormSchema = z.infer<typeof ZInviteTeamMembersFormSchema>;
Expand All @@ -70,7 +71,7 @@ export const InviteTeamMembersDialog = ({
...props
}: InviteTeamMembersDialogProps) => {
const [open, setOpen] = useState(false);

const { t } = useTranslation('web');
const { toast } = useToast();

const form = useForm<TInviteTeamMembersFormSchema>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { useRouter } from 'next/navigation';
import { zodResolver } from '@hookform/resolvers/zod';
import { Loader } from 'lucide-react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
import { z } from '@documenso/lib/i18n/settings';
import { trpc } from '@documenso/trpc/react';
import { Alert, AlertDescription } from '@documenso/ui/primitives/alert';
import { Button } from '@documenso/ui/primitives/button';
Expand Down Expand Up @@ -39,6 +39,7 @@ import {
SelectValue,
} from '@documenso/ui/primitives/select';
import { useToast } from '@documenso/ui/primitives/use-toast';
import { useTranslation } from '@documenso/lib/i18n/client';

export type TransferTeamDialogProps = {
teamId: number;
Expand All @@ -55,7 +56,7 @@ export const TransferTeamDialog = ({
}: TransferTeamDialogProps) => {
const router = useRouter();
const [open, setOpen] = useState(false);

const { t } = useTranslation('web');
const { toast } = useToast();

const { mutateAsync: requestTeamOwnershipTransfer } =
Expand All @@ -70,11 +71,11 @@ export const TransferTeamDialog = ({
teamId,
});

const confirmTransferMessage = `transfer ${teamName}`;
const confirmTransferMessage = t(`transfer-to-message`, {teamName});

const ZTransferTeamFormSchema = z.object({
teamName: z.literal(confirmTransferMessage, {
errorMap: () => ({ message: `You must enter '${confirmTransferMessage}' to proceed` }),
errorMap: () => ({ message: t(`you-must-enter`, {confirmTransferMessage})}),
}),
newOwnerUserId: z.string(),
clearPaymentMethods: z.boolean(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useRouter } from 'next/navigation';
import { zodResolver } from '@hookform/resolvers/zod';
import type * as DialogPrimitive from '@radix-ui/react-dialog';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import type { TeamEmail } from '@documenso/prisma/client';
import { trpc } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
Expand Down Expand Up @@ -38,7 +38,7 @@ export type UpdateTeamEmailDialogProps = {
} & Omit<DialogPrimitive.DialogProps, 'children'>;

const ZUpdateTeamEmailFormSchema = z.object({
name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),
name: z.string().trim().min(1, { message: 'please-enter-a-valid-name' }),
});

type TUpdateTeamEmailFormSchema = z.infer<typeof ZUpdateTeamEmailFormSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useEffect, useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import type * as DialogPrimitive from '@radix-ui/react-dialog';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { TEAM_MEMBER_ROLE_HIERARCHY, TEAM_MEMBER_ROLE_MAP } from '@documenso/lib/constants/teams';
import { z } from '@documenso/lib/i18n/settings';
import { isTeamRoleWithinUserHierarchy } from '@documenso/lib/utils/teams';
import { TeamMemberRole } from '@documenso/prisma/client';
import { trpc } from '@documenso/trpc/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useRouter } from 'next/navigation';
import { zodResolver } from '@hookform/resolvers/zod';
import { flushSync } from 'react-dom';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import { trpc } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { match } from 'ts-pattern';
import { renderSVG } from 'uqr';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import { downloadFile } from '@documenso/lib/client-only/download-file';
import { trpc } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useMemo } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { match } from 'ts-pattern';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import { downloadFile } from '@documenso/lib/client-only/download-file';
import { trpc } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/forms/forgot-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useRouter } from 'next/navigation';

import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import { trpc } from '@documenso/trpc/react';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
Expand Down
10 changes: 6 additions & 4 deletions apps/web/src/components/forms/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import type { User } from '@documenso/prisma/client';
import { TRPCClientError } from '@documenso/trpc/client';
import { trpc } from '@documenso/trpc/react';
Expand All @@ -20,6 +20,7 @@ import {
} from '@documenso/ui/primitives/form/form';
import { PasswordInput } from '@documenso/ui/primitives/password-input';
import { useToast } from '@documenso/ui/primitives/use-toast';
import { useTranslation } from '@documenso/lib/i18n/client';

export const ZPasswordFormSchema = z
.object({
Expand All @@ -28,7 +29,7 @@ export const ZPasswordFormSchema = z
repeatedPassword: ZPasswordSchema,
})
.refine((data) => data.password === data.repeatedPassword, {
message: 'Passwords do not match',
message: 'passwords-dont-match',
path: ['repeatedPassword'],
});

Expand All @@ -41,6 +42,7 @@ export type PasswordFormProps = {

export const PasswordForm = ({ className }: PasswordFormProps) => {
const { toast } = useToast();
const { t } = useTranslation('web');

const form = useForm<TPasswordFormSchema>({
values: {
Expand Down Expand Up @@ -99,7 +101,7 @@ export const PasswordForm = ({ className }: PasswordFormProps) => {
name="currentPassword"
render={({ field }) => (
<FormItem>
<FormLabel>Current Password</FormLabel>
<FormLabel>{t('current-password')}</FormLabel>
<FormControl>
<PasswordInput autoComplete="current-password" {...field} />
</FormControl>
Expand All @@ -113,7 +115,7 @@ export const PasswordForm = ({ className }: PasswordFormProps) => {
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormLabel>{t('password')}</FormLabel>
<FormControl>
<PasswordInput autoComplete="new-password" {...field} />
</FormControl>
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/forms/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useRouter } from 'next/navigation';

import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { z } from 'zod';

import { z } from '@documenso/lib/i18n/settings';
import type { User } from '@documenso/prisma/client';
import { TRPCClientError } from '@documenso/trpc/client';
import { trpc } from '@documenso/trpc/react';
Expand All @@ -25,8 +25,8 @@ import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
import { useToast } from '@documenso/ui/primitives/use-toast';

export const ZProfileFormSchema = z.object({
name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),
signature: z.string().min(1, 'Signature Pad cannot be empty'),
name: z.string().trim().min(1, { message: 'please-enter-a-valid-name' }),
signature: z.string().min(1, 'signature-pad-cannot-be-empty'),
});

export const ZTwoFactorAuthTokenSchema = z.object({
Expand Down
Loading

0 comments on commit 052b851

Please sign in to comment.