mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-03 19:40:08 -05:00
coderabbit feedback
This commit is contained in:
@@ -49,7 +49,6 @@ export const createContactAttributeKey = async (
|
||||
name,
|
||||
description,
|
||||
key,
|
||||
// If dataType is provided, use it; otherwise Prisma will use the default (text)
|
||||
...(dataType && { dataType }),
|
||||
};
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ export const EditContactAttributesModal = ({
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={["email", "userId", "firstName", "lastName"].includes(
|
||||
field.key
|
||||
watchedAttributes[index]?.key ?? ""
|
||||
)}
|
||||
size="sm"
|
||||
onClick={() => handleRemoveAttribute(index)}
|
||||
|
||||
@@ -15,13 +15,12 @@ export const parseDateFromParts = (part1: number, part2: number, part3: number):
|
||||
return new Date(part3, part1 - 1, part2);
|
||||
}
|
||||
|
||||
// Ambiguous - use additional heuristics
|
||||
if (part1 > 31 || part3 < 100) {
|
||||
// Likely YYYY-MM-DD format
|
||||
// Check for YYYY-MM-DD format
|
||||
if (part1 > 999) {
|
||||
return new Date(part1, part2 - 1, part3);
|
||||
}
|
||||
|
||||
// Default to American format MM-DD-YYYY
|
||||
// Default to MM-DD-YYYY
|
||||
return new Date(part3, part1 - 1, part2);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { TDateOperator, TSegmentFilterValue, TTimeUnit } from "@formbricks/types/segment";
|
||||
import { cn } from "@/lib/cn";
|
||||
import { toUTCDateString } from "@/modules/ee/contacts/segments/lib/date-utils";
|
||||
import { Input } from "@/modules/ui/components/input";
|
||||
import {
|
||||
Select,
|
||||
@@ -81,8 +82,7 @@ export function DateFilterValue({ operator, value, onChange, viewOnly }: DateFil
|
||||
disabled={viewOnly}
|
||||
value={betweenValue[0] ? betweenValue[0].split("T")[0] : ""}
|
||||
onChange={(e) => {
|
||||
const dateValue = e.target.value ? new Date(e.target.value).toISOString() : "";
|
||||
onChange([dateValue, betweenValue[1]]);
|
||||
onChange([toUTCDateString(e.target.value), betweenValue[1]]);
|
||||
}}
|
||||
/>
|
||||
<span className="text-sm text-slate-600">{t("common.and")}</span>
|
||||
@@ -92,8 +92,7 @@ export function DateFilterValue({ operator, value, onChange, viewOnly }: DateFil
|
||||
disabled={viewOnly}
|
||||
value={betweenValue[1] ? betweenValue[1].split("T")[0] : ""}
|
||||
onChange={(e) => {
|
||||
const dateValue = e.target.value ? new Date(e.target.value).toISOString() : "";
|
||||
onChange([betweenValue[0], dateValue]);
|
||||
onChange([betweenValue[0], toUTCDateString(e.target.value)]);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -111,8 +110,7 @@ export function DateFilterValue({ operator, value, onChange, viewOnly }: DateFil
|
||||
disabled={viewOnly}
|
||||
value={dateValue ? dateValue.split("T")[0] : ""}
|
||||
onChange={(e) => {
|
||||
const dateValue = e.target.value ? new Date(e.target.value).toISOString() : "";
|
||||
onChange(dateValue);
|
||||
onChange(toUTCDateString(e.target.value));
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -57,37 +57,49 @@ export const addTimeUnit = (date: Date, amount: number, unit: TTimeUnit): Date =
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the start of a day (00:00:00.000)
|
||||
* Gets the start of a day in UTC (00:00:00.000 UTC)
|
||||
* @param date - The date to get the start of
|
||||
* @returns A new Date object at the start of the day
|
||||
* @returns A new Date object at the start of the day in UTC
|
||||
*/
|
||||
export const startOfDay = (date: Date): Date => {
|
||||
const result = new Date(date);
|
||||
result.setHours(0, 0, 0, 0);
|
||||
result.setUTCHours(0, 0, 0, 0);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the end of a day (23:59:59.999)
|
||||
* Gets the end of a day in UTC (23:59:59.999 UTC)
|
||||
* @param date - The date to get the end of
|
||||
* @returns A new Date object at the end of the day
|
||||
* @returns A new Date object at the end of the day in UTC
|
||||
*/
|
||||
export const endOfDay = (date: Date): Date => {
|
||||
const result = new Date(date);
|
||||
result.setHours(23, 59, 59, 999);
|
||||
result.setUTCHours(23, 59, 59, 999);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if two dates are on the same day (ignoring time)
|
||||
* Checks if two dates are on the same day in UTC (ignoring time)
|
||||
* @param date1 - The first date
|
||||
* @param date2 - The second date
|
||||
* @returns True if the dates are on the same day
|
||||
* @returns True if the dates are on the same UTC day
|
||||
*/
|
||||
export const isSameDay = (date1: Date, date2: Date): boolean => {
|
||||
return (
|
||||
date1.getFullYear() === date2.getFullYear() &&
|
||||
date1.getMonth() === date2.getMonth() &&
|
||||
date1.getDate() === date2.getDate()
|
||||
date1.getUTCFullYear() === date2.getUTCFullYear() &&
|
||||
date1.getUTCMonth() === date2.getUTCMonth() &&
|
||||
date1.getUTCDate() === date2.getUTCDate()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a date-only string (YYYY-MM-DD) to an ISO string at midnight UTC.
|
||||
* This avoids timezone issues where local timezone conversion can shift the day.
|
||||
* @param dateString - The date string in YYYY-MM-DD format
|
||||
* @returns An ISO string at midnight UTC, or empty string if input is empty
|
||||
*/
|
||||
export const toUTCDateString = (dateString: string): string => {
|
||||
if (!dateString) return "";
|
||||
const [year, month, day] = dateString.split("-").map(Number);
|
||||
return new Date(Date.UTC(year, month - 1, day)).toISOString();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user