diff --git a/mango-frontend/package-lock.json b/mango-frontend/package-lock.json index a88e2cc..e02a887 100644 --- a/mango-frontend/package-lock.json +++ b/mango-frontend/package-lock.json @@ -29,6 +29,7 @@ "react": "^18.3.1", "react-day-picker": "^8.10.1", "react-dom": "^18.3.1", + "react-hot-toast": "^2.4.1", "react-redux": "^9.1.2", "react-router-dom": "^6.24.1", "tailwind-merge": "^2.4.0", @@ -2844,8 +2845,7 @@ "node_modules/csstype": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", - "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "devOptional": true + "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, "node_modules/date-fns": { "version": "3.6.0", @@ -3578,6 +3578,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/goober": { + "version": "2.1.14", + "resolved": "https://registry.npmjs.org/goober/-/goober-2.1.14.tgz", + "integrity": "sha512-4UpC0NdGyAFqLNPnhCT2iHpza2q+RAY3GV85a/mRPdzyPQMsj0KmMMuetdIkzWRbJ+Hgau1EZztq8ImmiMGhsg==", + "peerDependencies": { + "csstype": "^3.0.10" + } + }, "node_modules/graphemer": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", @@ -4445,6 +4453,21 @@ "react": "^18.3.1" } }, + "node_modules/react-hot-toast": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/react-hot-toast/-/react-hot-toast-2.4.1.tgz", + "integrity": "sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ==", + "dependencies": { + "goober": "^2.1.10" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": ">=16", + "react-dom": ">=16" + } + }, "node_modules/react-redux": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.1.2.tgz", diff --git a/mango-frontend/package.json b/mango-frontend/package.json index 1949eec..56e83b7 100644 --- a/mango-frontend/package.json +++ b/mango-frontend/package.json @@ -31,6 +31,7 @@ "react": "^18.3.1", "react-day-picker": "^8.10.1", "react-dom": "^18.3.1", + "react-hot-toast": "^2.4.1", "react-redux": "^9.1.2", "react-router-dom": "^6.24.1", "tailwind-merge": "^2.4.0", diff --git a/mango-frontend/src/components/Create Issue/CreateIssue.tsx b/mango-frontend/src/components/Create Issue/CreateIssue.tsx index d199500..770e91c 100644 --- a/mango-frontend/src/components/Create Issue/CreateIssue.tsx +++ b/mango-frontend/src/components/Create Issue/CreateIssue.tsx @@ -180,14 +180,10 @@ export function CreateIssue({ isOpen, onClose }: CreateIssueProps) { const resultAction = await dispatch(createIssue(issue)); if (createIssue.fulfilled.match(resultAction)) { - try { toast({ title: "Issue Created", description: "A new issue has been successfully created.", }); - } catch (error) { - console.log(error) - } onClose(); } else { toast({ diff --git a/mango-frontend/src/components/Create Sprint/CreateSprint.tsx b/mango-frontend/src/components/Create Sprint/CreateSprint.tsx index 4015fb5..74f3b55 100644 --- a/mango-frontend/src/components/Create Sprint/CreateSprint.tsx +++ b/mango-frontend/src/components/Create Sprint/CreateSprint.tsx @@ -12,61 +12,95 @@ import { } from "@/components/ui/dialog" import { Textarea } from "@/components/ui/textarea" import DatePicker from './DatePicker' +import { isBefore, startOfToday } from 'date-fns' +import { useDispatch } from 'react-redux' +import { AppDispatch } from '@/redux/store' +import { createSprintDataType } from '@/types' +import { clearState, createSprint } from '@/redux/slices/sprintSlice' +import toast from 'react-hot-toast' +import useInput from '@/hooks/useInput' interface CreateSprintProps { isOpen: boolean; onClose: () => void; } -export type InputReturnType = [ - string, - (e: React.ChangeEvent) => void, - () => void -]; - -const useInput = (initialValue: string): InputReturnType => { - const [value, setValue] = React.useState(initialValue); - const handleChange = (e: React.ChangeEvent): void => { - setValue(e.target.value); - }; - - const reset = () => setValue(initialValue); - return [value, handleChange, reset] as const; -}; - const CreateSprint: React.FC = ({ isOpen, onClose }) => { - const [title, handleTitleChange, resetTitle] = useInput(''); + const [name, handleNameChange, resetName] = useInput(''); const [description, handleDescriptionChange, resetDescription] = useInput(''); const [startDate, setStartDate] = React.useState(null); const [endDate, setEndDate] = React.useState(null); + const [status, setStatus] = React.useState<'ongoing' | 'upcoming' | 'completed'>('ongoing'); + const today = startOfToday(); + const dispatch = useDispatch(); + + // const { message, error } = useSelector((state: RootState) => state.sprints); + + // console.log("message: ", message); + // console.log("error: ", error) - console.log(title); - console.log(description) - console.log(startDate); - console.log(endDate) + React.useEffect(() => { + if (startDate && isBefore(today, startDate)) { + setStatus('upcoming'); + } + }, [startDate, today]); + const calculateDays = (): number | null => { + if (startDate && endDate) { + const start = new Date(startDate); + const end = new Date(endDate); + const diffInTime = end.getTime() - start.getTime(); + const diffInDays = Math.ceil(diffInTime / (1000 * 3600 * 24) + 1); + return diffInDays; + } + return null; + }; + + console.log(calculateDays()) const handleClose = (): void => { - resetTitle(); + resetName(); resetDescription(); setStartDate(null) setEndDate(null) onClose(); } + const handleSubmit = async (e: React.FormEvent): Promise => { + e.preventDefault(); + + const sprint: createSprintDataType = { + name, + description, + start_date: startDate, + end_date: endDate, + status + }; + const resultAction = await dispatch(createSprint(sprint)); + if (createSprint.fulfilled.match(resultAction)) { + toast.success(resultAction?.payload?.message); + dispatch(clearState()); + } else if (createSprint.rejected.match(resultAction)) { + toast.error('Failed to create Sprint'); + } else { + toast.error('Unexpected error occurred'); + } + onClose(); + } + return (
-
✨Atlas
+
✨  Atlas
Create Cycle
- +