Skip to content

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

Fix custom date note

François Zaninotto8186b36631fd
diff --git a/src/notes/NoteInputs.tsx b/src/notes/NoteInputs.tsx
index 80f4af4c..f660fd9a 100644
--- a/src/notes/NoteInputs.tsx
+++ b/src/notes/NoteInputs.tsx
@@ -6,8 +6,10 @@ import {
SelectInput,
TextInput,
} from 'react-admin';
-import { useConfigurationContext } from '../root/ConfigurationContext';
import { useState } from 'react';
+import { useFormContext } from 'react-hook-form';
+
+import { useConfigurationContext } from '../root/ConfigurationContext';
import { formatNoteDate, getCurrentDate } from './utils';
import { Status } from '../misc/Status';
@@ -19,6 +21,7 @@ export const NoteInputs = ({
edition?: boolean;
}) => {
const { noteStatuses } = useConfigurationContext();
+ const { setValue } = useFormContext();
const [displayMore, setDisplayMore] = useState(false);
return (
<>
@@ -38,6 +41,7 @@ export const NoteInputs = ({
href="#"
onClick={e => {
setDisplayMore(!displayMore);
+ setValue('date', getCurrentDate());
e.preventDefault();
}}
>
@@ -65,7 +69,6 @@ export const NoteInputs = ({
<DateTimeInput
source="date"
label="Date"
- defaultValue={getCurrentDate()}
helperText={false}
parse={formatNoteDate}
/>
diff --git a/src/notes/utils.ts b/src/notes/utils.ts
index a6e1fcf8..834d3eb3 100644
--- a/src/notes/utils.ts
+++ b/src/notes/utils.ts
@@ -1,9 +1,13 @@
export const getCurrentDate = () => {
const now = new Date();
+ now.setSeconds(0);
+ now.setMilliseconds(0);
return now.toISOString();
};
export const formatNoteDate = (dateString: string) => {
const date = new Date(dateString);
+ date.setSeconds(0);
+ date.setMilliseconds(0);
return date.toISOString();
};