mirror of
https://github.com/documenso/documenso.git
synced 2025-11-18 18:51:37 +10:00
chore: code changes based of review
This commit is contained in:
@ -100,9 +100,7 @@ export const ResendDocumentActionItem = ({
|
||||
});
|
||||
|
||||
setIsOpen(false);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
} catch {
|
||||
toast({
|
||||
title: _(msg`Something went wrong`),
|
||||
description: _(msg`This document could not be re-sent at this time. Please try again.`),
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { msg } from '@lingui/macro';
|
||||
import { Trans, msg } from '@lingui/macro';
|
||||
import { useLingui } from '@lingui/react';
|
||||
|
||||
import { Input } from '@documenso/ui/primitives/input';
|
||||
@ -25,12 +25,14 @@ export const DocumentExpirySettings = ({ onChange }: DocumentExpirySettingsProps
|
||||
|
||||
const handleExpiryValueChange = (value: string) => {
|
||||
const parsedValue = parseInt(value, 10);
|
||||
if (isNaN(parsedValue)) {
|
||||
|
||||
if (Number.isNaN(parsedValue) || parsedValue <= 0) {
|
||||
setExpiryValue(undefined);
|
||||
return;
|
||||
} else {
|
||||
setExpiryValue(parsedValue);
|
||||
}
|
||||
onChange(parsedValue, expiryUnit);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExpiryUnitChange = (value: 'day' | 'week' | 'month') => {
|
||||
@ -50,12 +52,18 @@ export const DocumentExpirySettings = ({ onChange }: DocumentExpirySettingsProps
|
||||
/>
|
||||
<Select value={expiryUnit} onValueChange={handleExpiryUnitChange}>
|
||||
<SelectTrigger className="text-muted-foreground">
|
||||
<SelectValue placeholder="Select..." />
|
||||
<SelectValue placeholder={_(msg`Select...`)} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="day">Day</SelectItem>
|
||||
<SelectItem value="week">Week</SelectItem>
|
||||
<SelectItem value="month">Month</SelectItem>
|
||||
<SelectItem value="day">
|
||||
<Trans>Day</Trans>
|
||||
</SelectItem>
|
||||
<SelectItem value="week">
|
||||
<Trans>Week</Trans>
|
||||
</SelectItem>
|
||||
<SelectItem value="month">
|
||||
<Trans>Month</Trans>
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
@ -106,23 +106,6 @@ export const resendDocument = async ({
|
||||
return;
|
||||
}
|
||||
|
||||
let newExpiryDate: Date | null = null;
|
||||
if (recipient.expired) {
|
||||
const durationInMs = recipient.expired.getTime() - document.updatedAt.getTime();
|
||||
newExpiryDate = new Date(Date.now() + durationInMs);
|
||||
|
||||
await prisma.recipient.update({
|
||||
where: { id: recipient.id },
|
||||
data: {
|
||||
expired: newExpiryDate,
|
||||
signingStatus:
|
||||
recipient.signingStatus === SigningStatus.EXPIRED
|
||||
? SigningStatus.NOT_SIGNED
|
||||
: recipient.signingStatus,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const i18n = await getI18nInstance(document.documentMeta?.language);
|
||||
|
||||
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
||||
@ -183,6 +166,22 @@ export const resendDocument = async ({
|
||||
|
||||
await prisma.$transaction(
|
||||
async (tx) => {
|
||||
if (recipient.expired) {
|
||||
const durationInMs = recipient.expired.getTime() - document.updatedAt.getTime();
|
||||
const newExpiryDate = new Date(Date.now() + durationInMs);
|
||||
|
||||
await tx.recipient.update({
|
||||
where: { id: recipient.id },
|
||||
data: {
|
||||
expired: newExpiryDate,
|
||||
signingStatus:
|
||||
recipient.signingStatus === SigningStatus.EXPIRED
|
||||
? SigningStatus.NOT_SIGNED
|
||||
: recipient.signingStatus,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const [html, text] = await Promise.all([
|
||||
renderEmailWithI18N(template, {
|
||||
lang: document.documentMeta?.language,
|
||||
|
||||
@ -31,10 +31,9 @@ export const updateExpiredRecipients = async (documentId: number) => {
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
expiredRecipients.map(async (recipient) =>
|
||||
prisma.documentAuditLog.create({
|
||||
data: createDocumentAuditLogData({
|
||||
await prisma.documentAuditLog.createMany({
|
||||
data: expiredRecipients.map((recipient) =>
|
||||
createDocumentAuditLogData({
|
||||
type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_EXPIRED,
|
||||
documentId,
|
||||
user: {
|
||||
@ -42,15 +41,14 @@ export const updateExpiredRecipients = async (documentId: number) => {
|
||||
email: recipient.email,
|
||||
},
|
||||
data: {
|
||||
recipientEmail: recipient.email,
|
||||
recipientName: recipient.name,
|
||||
recipientId: recipient.id,
|
||||
recipientRole: recipient.role,
|
||||
recipientId: recipient.id,
|
||||
recipientEmail: recipient.email,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return expiredRecipients;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { SigningStatus } from '@documenso/prisma/client';
|
||||
|
||||
@ -16,8 +18,8 @@ export const isRecipientExpired = async ({ token }: IsRecipientExpiredOptions) =
|
||||
throw new Error('Recipient not found');
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const hasExpired = recipient.expired && new Date(recipient.expired) <= now;
|
||||
const now = DateTime.now();
|
||||
const hasExpired = recipient.expired && DateTime.fromJSDate(recipient.expired) <= now;
|
||||
|
||||
if (hasExpired && recipient.signingStatus !== SigningStatus.EXPIRED) {
|
||||
await prisma.recipient.update({
|
||||
|
||||
@ -103,9 +103,9 @@ export const setRecipientExpiry = async ({
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
return persisted;
|
||||
}
|
||||
});
|
||||
|
||||
return updatedRecipient;
|
||||
|
||||
@ -375,7 +375,7 @@ export const formatDocumentAuditLogAction = (
|
||||
.with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_EXPIRED }, () => {
|
||||
const userName = prefix || _(msg`Recipient`);
|
||||
|
||||
const result = msg`${userName} expired`;
|
||||
const result = msg`${userName}'s signing period has expired`;
|
||||
|
||||
return {
|
||||
anonymous: result,
|
||||
|
||||
@ -84,7 +84,7 @@ export type TRejectDocumentWithTokenMutationSchema = z.infer<
|
||||
export const ZSetSignerExpirySchema = z.object({
|
||||
documentId: z.number(),
|
||||
signerId: z.number(),
|
||||
expiry: z.date(),
|
||||
expiry: z.date().min(new Date(), { message: 'Expiry date must be in the future' }),
|
||||
teamId: z.number().optional(),
|
||||
});
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ export const ZAddSignerSchema = z.object({
|
||||
.min(1),
|
||||
name: z.string(),
|
||||
role: z.nativeEnum(RecipientRole),
|
||||
expiry: z.date().optional(),
|
||||
expiry: z.date().min(new Date(), { message: 'Expiry date must be in the future' }).optional(),
|
||||
signingOrder: z.number().optional(),
|
||||
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(ZRecipientActionAuthTypesSchema.optional()),
|
||||
});
|
||||
|
||||
@ -164,6 +164,8 @@ export function DocumentExpiryDialog({
|
||||
case 'months':
|
||||
expiryDate = addMonths(now, values.amount);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid unit: ${values.unit}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,10 +175,10 @@ export function DocumentExpiryDialog({
|
||||
expiry: expiryDate,
|
||||
});
|
||||
|
||||
// TODO: Implement logic to update expiry when resending document
|
||||
// TODO: Duncan => Implement logic to update expiry when resending document
|
||||
// This should be handled on the server-side when a document is resent
|
||||
|
||||
// TODO: Implement logic to mark recipients as expired
|
||||
// TODO: Duncan => Implement logic to mark recipients as expired
|
||||
// This should be a scheduled task or part of the completion process on the server
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user