Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

code review

ThieryMichel27b372197bd7
diff --git a/src/components/atomic-crm/deals/dealUtils.spec.ts b/src/components/atomic-crm/deals/dealUtils.spec.ts
index 6d89f378..8ae4fffd 100644
--- a/src/components/atomic-crm/deals/dealUtils.spec.ts
+++ b/src/components/atomic-crm/deals/dealUtils.spec.ts
@@ -9,14 +9,17 @@ describe("formatISODateString", () => {
it("should not shift the date for different timezone", () => {
const originalTZ = process.env.TZ;
- process.env.TZ = "America/New_York";
- const isoDate = "2024-06-15";
- expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
- process.env.TZ = "Asia/Tokyo";
- expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
- process.env.TZ = "UTC";
- expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
- process.env.TZ = originalTZ; // Reset timezone after test
+ try {
+ process.env.TZ = "America/New_York";
+ const isoDate = "2024-06-15";
+ expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
+ process.env.TZ = "Asia/Tokyo";
+ expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
+ process.env.TZ = "UTC";
+ expect(formatISODateString(isoDate)).toBe("Jun 15, 2024");
+ } finally {
+ process.env.TZ = originalTZ; // Ensure timezone is reset even if test fails
+ }
});
it("throw for an invalid date string", () => {
diff --git a/src/components/atomic-crm/deals/dealUtils.ts b/src/components/atomic-crm/deals/dealUtils.ts
index 462e20d9..581d5396 100644
--- a/src/components/atomic-crm/deals/dealUtils.ts
+++ b/src/components/atomic-crm/deals/dealUtils.ts
@@ -33,7 +33,7 @@ export function formatISODateString(dateString: string) {
if (!isoDateStringRegex.test(dateString)) {
throw new Error("Invalid date format. Expected YYYY-MM-DD.");
}
- // Some browsers Will consider a date in the format YYYY-MM-DD as UTC, which can cause off-by-one-day issues depending on the user's timezone.
+ // Some browsers will consider a date in the format YYYY-MM-DD as UTC, which can cause off-by-one-day issues depending on the user's timezone.
// To avoid this, we can parse the date components manually and create a date object in the local timezone.
const [year, month, day] = dateString.split("-").map(Number);
const date = new Date(year, month - 1, day);
diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
index 3cae55c2..0db67084 100644
--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
@@ -23,7 +23,9 @@ export const generateDeals = (db: Db): Deal[] => {
const expected_closing_date = randomDate(
new Date(created_at),
add(new Date(created_at), { months: 6 }),
- ).toISOString();
+ )
+ .toISOString()
+ .split("T")[0];
return {
id,
diff --git a/src/components/atomic-crm/tasks/AddTask.tsx b/src/components/atomic-crm/tasks/AddTask.tsx
index bcebaa0d..58c282bc 100644
--- a/src/components/atomic-crm/tasks/AddTask.tsx
+++ b/src/components/atomic-crm/tasks/AddTask.tsx
@@ -100,7 +100,7 @@ export const AddTask = ({
record={{
type: "None",
contact_id: contact?.id,
- due_date: new Date().toISOString().slice(0, 10),
+ due_date: new Date().toISOString(),
sales_id: identity.id,
}}
mutationOptions={{ onSuccess: handleSuccess }}
diff --git a/supabase/migrations/20260226163952_deals_expected_closing_date_date_only.sql b/supabase/migrations/20260226163952_deals_expected_closing_date_date_only.sql
index 17935a75..ad9f3b75 100644
--- a/supabase/migrations/20260226163952_deals_expected_closing_date_date_only.sql
+++ b/supabase/migrations/20260226163952_deals_expected_closing_date_date_only.sql
@@ -1,3 +1,3 @@
-- Migrating from timestamp with timezone to date only for expected_closing_date as we don't need the precision
-- And by only handling the date part in the client it caused conversion issues for users in different timezones
-ALTER table "public"."deals" ALTER COLUMN "expected_closing_date" TYPE date USING "expected_closing_date"::date;
+ALTER table "public"."deals" ALTER COLUMN "expected_closing_date" TYPE date USING ("expected_closing_date" AT TIME ZONE 'UTC')::date;