fix: default to user timezone (#1559)
Passes the timezone of the user uploading the document/template via the UI to the server. If the user uploads a document/template via the API and doesn't set a timezone, it defaults to `Etc/UTC`.
This commit is contained in:
@@ -12,6 +12,7 @@ import { useSession } from 'next-auth/react';
|
|||||||
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
|
||||||
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
|
import { DEFAULT_DOCUMENT_TIME_ZONE, TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
||||||
import { AppError } from '@documenso/lib/errors/app-error';
|
import { AppError } from '@documenso/lib/errors/app-error';
|
||||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
||||||
@@ -33,6 +34,9 @@ export type UploadDocumentProps = {
|
|||||||
export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
|
export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const analytics = useAnalytics();
|
const analytics = useAnalytics();
|
||||||
|
const userTimezone =
|
||||||
|
TIME_ZONES.find((timezone) => timezone === Intl.DateTimeFormat().resolvedOptions().timeZone) ??
|
||||||
|
DEFAULT_DOCUMENT_TIME_ZONE;
|
||||||
|
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
|
||||||
@@ -73,6 +77,7 @@ export const UploadDocument = ({ className, team }: UploadDocumentProps) => {
|
|||||||
title: file.name,
|
title: file.name,
|
||||||
documentDataId,
|
documentDataId,
|
||||||
teamId: team?.id,
|
teamId: team?.id,
|
||||||
|
timezone: userTimezone,
|
||||||
});
|
});
|
||||||
|
|
||||||
void refreshLimits();
|
void refreshLimits();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export type CreateDocumentOptions = {
|
|||||||
documentDataId: string;
|
documentDataId: string;
|
||||||
formValues?: Record<string, string | number | boolean>;
|
formValues?: Record<string, string | number | boolean>;
|
||||||
normalizePdf?: boolean;
|
normalizePdf?: boolean;
|
||||||
|
timezone?: string;
|
||||||
requestMetadata?: RequestMetadata;
|
requestMetadata?: RequestMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ export const createDocument = async ({
|
|||||||
normalizePdf,
|
normalizePdf,
|
||||||
formValues,
|
formValues,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
|
timezone,
|
||||||
}: CreateDocumentOptions): Promise<TCreateDocumentResponse> => {
|
}: CreateDocumentOptions): Promise<TCreateDocumentResponse> => {
|
||||||
const user = await prisma.user.findFirstOrThrow({
|
const user = await prisma.user.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
@@ -150,6 +152,7 @@ export const createDocument = async ({
|
|||||||
create: {
|
create: {
|
||||||
language: team?.teamGlobalSettings?.documentLanguage,
|
language: team?.teamGlobalSettings?.documentLanguage,
|
||||||
typedSignatureEnabled: team?.teamGlobalSettings?.typedSignatureEnabled,
|
typedSignatureEnabled: team?.teamGlobalSettings?.typedSignatureEnabled,
|
||||||
|
timezone: timezone,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export const documentRouter = router({
|
|||||||
.input(ZCreateDocumentMutationSchema)
|
.input(ZCreateDocumentMutationSchema)
|
||||||
.output(ZCreateDocumentResponseSchema)
|
.output(ZCreateDocumentResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { title, documentDataId, teamId } = input;
|
const { title, documentDataId, teamId, timezone } = input;
|
||||||
|
|
||||||
const { remaining } = await getServerLimits({ email: ctx.user.email, teamId });
|
const { remaining } = await getServerLimits({ email: ctx.user.email, teamId });
|
||||||
|
|
||||||
@@ -198,6 +198,7 @@ export const documentRouter = router({
|
|||||||
title,
|
title,
|
||||||
documentDataId,
|
documentDataId,
|
||||||
normalizePdf: true,
|
normalizePdf: true,
|
||||||
|
timezone,
|
||||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export const ZCreateDocumentMutationSchema = z.object({
|
|||||||
title: z.string().min(1),
|
title: z.string().min(1),
|
||||||
documentDataId: z.string().min(1),
|
documentDataId: z.string().min(1),
|
||||||
teamId: z.number().optional(),
|
teamId: z.number().optional(),
|
||||||
|
timezone: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TCreateDocumentMutationSchema = z.infer<typeof ZCreateDocumentMutationSchema>;
|
export type TCreateDocumentMutationSchema = z.infer<typeof ZCreateDocumentMutationSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user