Skip to content

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

Fix(crm): date validation in DealInputs and DealShow

Anthony Rimetfcaee6aa1b7b
diff --git a/src/deals/DealInputs.tsx b/src/deals/DealInputs.tsx
index 850b0269..14bcc342 100644
--- a/src/deals/DealInputs.tsx
+++ b/src/deals/DealInputs.tsx
@@ -141,6 +141,7 @@ const DealMiscInputs = () => {
fullWidth
validate={[validateRequired]}
helperText={false}
+ inputProps={{ max: '9999-12-31' }}
/>
<SelectInput
source="stage"
diff --git a/src/deals/DealShow.tsx b/src/deals/DealShow.tsx
index 125483e9..230cfe97 100644
--- a/src/deals/DealShow.tsx
+++ b/src/deals/DealShow.tsx
@@ -9,7 +9,7 @@ import {
Typography,
} from '@mui/material';
import { useMutation } from '@tanstack/react-query';
-import { format } from 'date-fns';
+import { format, isValid } from 'date-fns';
import {
DeleteButton,
EditButton,
@@ -59,6 +59,7 @@ const DealShowContent = ({ handleClose }: { handleClose: () => void }) => {
const { dealStages } = useConfigurationContext();
const record = useRecordContext<Deal>();
if (!record) return null;
+
return (
<>
<DialogCloseButton
@@ -117,10 +118,18 @@ const DealShowContent = ({ handleClose }: { handleClose: () => void }) => {
gap={1}
>
<Typography variant="body2">
- {format(
- record.expected_closing_date,
- 'PP'
- )}
+ {isValid(
+ new Date(
+ record.expected_closing_date
+ )
+ )
+ ? format(
+ new Date(
+ record.expected_closing_date
+ ),
+ 'PP'
+ )
+ : 'Invalid date'}
</Typography>
{new Date(record.expected_closing_date) <
new Date() ? (
diff --git a/src/notes/NoteCreate.tsx b/src/notes/NoteCreate.tsx
index d6a9923e..86b389c1 100644
--- a/src/notes/NoteCreate.tsx
+++ b/src/notes/NoteCreate.tsx
@@ -62,16 +62,23 @@ const NoteCreateButton = ({
if (!record || !identity) return null;
+ const resetValues: {
+ date: string;
+ text: null;
+ attachments: null;
+ status?: string;
+ } = {
+ date: getCurrentDate(),
+ text: null,
+ attachments: null,
+ };
+
+ if (reference === 'contacts') {
+ resetValues.status = 'warm';
+ }
+
const handleSuccess = (data: any) => {
- reset(
- {
- date: getCurrentDate(),
- text: null,
- status: 'warm',
- attachments: null,
- },
- { keepValues: false }
- );
+ reset(resetValues, { keepValues: false });
refetch();
update(reference, {
id: (record && record.id) as unknown as Identifier,