Skip to content

Commit

Permalink
🥭 Create Sprint Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeManSu committed Jul 11, 2024
1 parent 32095e4 commit 28e8d88
Show file tree
Hide file tree
Showing 15 changed files with 457 additions and 24 deletions.
54 changes: 54 additions & 0 deletions mango-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mango-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-toast": "^1.2.1",
"@reduxjs/toolkit": "^2.2.6",
"@tanstack/react-table": "^8.19.2",
"@types/redux-persist": "^4.3.1",
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"lucide-react": "^0.402.0",
"react": "^18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.24.1",
Expand Down
11 changes: 2 additions & 9 deletions mango-frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import './App.css'
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
// import Drawer from './components/Drawer';
// import { Button } from "@/components/ui/button"
// import { Button } from './components/ui/Button';
// import { Button } from "./components/ui/button"

// import { Button } from "@/components/ui/button"
import HomePage from './Pages/HomePage';
import SprintsPage from './Pages/SprintsPage';

function App() {

Expand All @@ -15,9 +10,7 @@ function App() {
<Router>
<Routes>
<Route path="/" element={<HomePage />} />
{/* <Route path="/trends" element={<PollTrends />} /> */}
{/* <Drawer /> */}
{/* <Button /> */}
<Route path="/sprints" element={<SprintsPage />} />
</Routes>

</Router>
Expand Down
15 changes: 15 additions & 0 deletions mango-frontend/src/Pages/SprintsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Sidebar } from '@/components/sidebar/sidebar'
import Sprints from '@/components/Sprints/Sprints'
import React from 'react'

const SprintsPage: React.FC = () => {
return (
<div className='flex'>
<Sidebar />
{/* <IssueTable columns={columns} data={issues} /> */}
<Sprints />
</div>
)
}

export default SprintsPage
101 changes: 101 additions & 0 deletions mango-frontend/src/components/Create Sprint/CreateSprint.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from 'react'
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { Textarea } from "@/components/ui/textarea"
import DatePicker from './DatePicker'

interface CreateSprintProps {
isOpen: boolean;
onClose: () => void;
}

export type InputReturnType = [
string,
(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void,
() => void
];

const useInput = (initialValue: string): InputReturnType => {
const [value, setValue] = React.useState(initialValue);
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {
setValue(e.target.value);
};

const reset = () => setValue(initialValue);
return [value, handleChange, reset] as const;
};

const CreateSprint: React.FC<CreateSprintProps> = ({ isOpen, onClose }) => {

const [title, handleTitleChange, resetTitle] = useInput('');
const [description, handleDescriptionChange, resetDescription] = useInput('');
const [startDate, setStartDate] = React.useState<Date | null>(null);
const [endDate, setEndDate] = React.useState<Date | null>(null);

console.log(title);
console.log(description)
console.log(startDate);
console.log(endDate)


const handleClose = (): void => {
resetTitle();
resetDescription();
setStartDate(null)
setEndDate(null)
onClose();
}

return (
<div>
<Dialog open={isOpen} onOpenChange={handleClose}>
<DialogContent className="">
<DialogHeader>
<div className='w-fit flex gap-3 items-center'>
<div className='border-2 cursor-pointer p-[2px] rounded-md text-[15px]'>✨Atlas</div>
<DialogTitle>Create Cycle</DialogTitle>
</div>
<DialogDescription />
<div className='pt-2 flex flex-col gap-3'>
<Input id='title' type={'text'} placeholder='Title...' value={title} onChange={handleTitleChange} />
<Textarea placeholder='Description' value={description} onChange={handleDescriptionChange} />
</div>
<div className='pt-[10px]'>
<DatePicker
startDate={startDate}
endDate={endDate}
setStartDate={setStartDate}
setEndDate={setEndDate}
/>
</div>
</DialogHeader>
<DialogFooter className="sm:justify-end">
<DialogClose asChild>
<Button className='border-2 bg-white' type="button" variant="secondary" size={'md'}
onClick={handleClose}>
Cancel
</Button>
</DialogClose>
<Button type="button" variant="secondary" size={'md'}
onClick={handleClose}
className='bg-blue-500 hover:bg-blue-500 text-white'
>
Create Issue
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}

export default CreateSprint
81 changes: 81 additions & 0 deletions mango-frontend/src/components/Create Sprint/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as React from "react"
import { addDays, isBefore, startOfToday } from "date-fns"
import { Calendar as CalendarIcon } from "lucide-react"
import { DateRange } from "react-day-picker"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover"

interface DatePickerProps extends React.HTMLAttributes<HTMLDivElement> {
startDate: Date | null;
endDate: Date | null;
setStartDate: (date: Date | null) => void;
setEndDate: (date: Date | null) => void
}

const DatePicker: React.FC<DatePickerProps> = ({ className, startDate, endDate, setStartDate, setEndDate }) => {

const [date, setDate] = React.useState<DateRange | undefined>({
from: startDate || undefined,
to: endDate ? addDays(endDate, 20) : undefined
});

const handleSelect = (range: DateRange | undefined) => {
setDate(range);
setStartDate(range?.from || null);
setEndDate(range?.to || null);
};

const formatDate = (date: Date) => {
return date.toLocaleDateString('en-US', {
month: 'short',
day: '2-digit',
year: 'numeric'
})
}

const dateRangeText = startDate && endDate ? `${formatDate(startDate)} &nbsp; 🡒 &nbsp; ${formatDate(endDate)}` : "Start date &nbsp; 🡒 &nbsp; End date";

return (
<div className={cn("grid gap-2", className)}>
<Popover>
<PopoverTrigger asChild>
<Button
id="date"
size='datePicker'
variant={"outline"}
className={cn(
"w-fit justify-start text-left font-normal",
!date && "text-muted-foreground"
)}
>
<CalendarIcon className="mr-2 h-4 w-4" />
<span dangerouslySetInnerHTML={{ __html: dateRangeText }} />
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="range"
defaultMonth={date?.from || startOfToday()}
selected={date}
onSelect={handleSelect}
numberOfMonths={1}
showOutsideDays={false}
disabled={(date) => isBefore(date, startOfToday())}
classNames={{
day_selected: "bg-blue-500 text-white",
day_range_middle: "bg-blue-200 no-hove",
}}
/>
</PopoverContent>
</Popover>
</div>
)
}

export default DatePicker;
Loading

0 comments on commit 28e8d88

Please sign in to comment.