generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 14
feat(tasks): add defer task functionality and UI components #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b20af4b
feat(tasks): add defer task functionality and UI components
AnujChhikara 22151b7
refactor(tasks): enhance task deferral functionality and UI
AnujChhikara d29c313
feat(tasks): add DEFERRED status to task management
AnujChhikara 4c38b51
feat(todo): enhance task deferral UI and functionality
AnujChhikara fd9c0aa
fix(tasks): change deferredTill property to be required in DeferTaskR…
AnujChhikara e67d688
refactor(tasks): rename deferredTask to deferTask for consistency
AnujChhikara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| 'use client' | ||
|
|
||
| import { TasksApi } from '@/api/tasks/tasks.api' | ||
| import { Button } from '@/components/ui/button' | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog' | ||
| import { Label } from '@/components/ui/label' | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
| import { useState } from 'react' | ||
| import { toast } from 'sonner' | ||
| import { TTodoFormData } from './create-edit-todo-form' | ||
| import { DatePickerSelect } from './date-picker-select' | ||
|
|
||
| type DeferredTaskButtonProps = { | ||
| todo: Partial<TTodoFormData> | ||
| open: boolean | ||
| setOpen: (open: boolean) => void | ||
| } | ||
|
|
||
| export const DeferredTaskButton = ({ todo, open, setOpen }: DeferredTaskButtonProps) => { | ||
| const [deferredTill, setDeferredTill] = useState<Date>() | ||
| const queryClient = useQueryClient() | ||
|
|
||
| const deferTaskMutation = useMutation({ | ||
| mutationFn: TasksApi.deferTask.fn, | ||
| onSuccess: () => { | ||
| toast.success('Task deferred successfully') | ||
| void queryClient.invalidateQueries({ queryKey: TasksApi.getTasks.key() }) | ||
| void queryClient.invalidateQueries({ | ||
| queryKey: TasksApi.getTasks.key({ status: 'DEFERRED' }), | ||
| }) | ||
| setOpen(false) | ||
| setDeferredTill(undefined) | ||
| }, | ||
| onError: () => { | ||
| toast.error('Failed to defer task, please try again') | ||
| }, | ||
| }) | ||
|
|
||
| const handleDeferTask = () => { | ||
| if (!deferredTill) { | ||
| toast.error('Please select a defer date') | ||
| return | ||
| } | ||
|
|
||
| deferTaskMutation.mutate({ | ||
| taskId: todo.taskId ?? '', | ||
| deferredTill: deferredTill.toISOString(), | ||
| }) | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={setOpen}> | ||
| <DialogContent className="sm:max-w-[425px]"> | ||
| <DialogHeader> | ||
| <DialogTitle>Defer Todo</DialogTitle> | ||
| <DialogDescription> | ||
| Defer "{todo.title}" to a later date. The todo will be moved to your deferred | ||
| todos. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="grid gap-4 py-4"> | ||
| <div className="grid grid-cols-4 items-center gap-4"> | ||
| <Label htmlFor="deferredTill" className="text-right"> | ||
| Defer Until | ||
| </Label> | ||
| <div className="col-span-3"> | ||
| <DatePickerSelect | ||
| value={deferredTill} | ||
| onChange={setDeferredTill} | ||
| isDateDisabled={(date) => date <= new Date()} | ||
AnujChhikara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <DialogFooter> | ||
| <Button | ||
| type="submit" | ||
| onClick={handleDeferTask} | ||
| disabled={!deferredTill || deferTaskMutation.isPending} | ||
| > | ||
| {deferTaskMutation.isPending ? 'Deferring...' : 'Defer Todo'} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use client' | ||
|
|
||
| import { TasksApi } from '@/api/tasks/tasks.api' | ||
| import { GetTaskReqDto } from '@/api/tasks/tasks.types' | ||
| import { CommonPageError } from '@/components/common-page-error' | ||
| import { TodoListTable } from '@/components/todo-list-table' | ||
| import { useQuery } from '@tanstack/react-query' | ||
| import { useSearchParams } from 'next/navigation' | ||
| import { DashboardTasksTableTabs as TabsConstants } from '../constants' | ||
|
|
||
| export const DashboardDeferredTable = () => { | ||
| const searchParams = useSearchParams() | ||
| const tab = searchParams.get('tab') | ||
| const status = searchParams.get('status') | ||
| const isInvalidCombination = tab === TabsConstants.Deferred && status === 'Done' | ||
AnujChhikara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const queryParams: GetTaskReqDto = { status: 'DEFERRED' } | ||
|
|
||
| const { data, isLoading, isError } = useQuery({ | ||
| queryKey: TasksApi.getTasks.key(queryParams), | ||
| queryFn: () => TasksApi.getTasks.fn(queryParams), | ||
| select: (data) => data.tasks, | ||
| }) | ||
|
|
||
| if (isError || isInvalidCombination) { | ||
| return <CommonPageError /> | ||
| } | ||
AnujChhikara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return <TodoListTable showActions isLoading={isLoading} tasks={data} /> | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.