Skip to content

Commit

Permalink
fix(task-desc): can not update task's description
Browse files Browse the repository at this point in the history
  • Loading branch information
hudy9x committed May 2, 2024
1 parent 6d1585c commit cedff71
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useEditor, EditorContent, BubbleMenu } from '@tiptap/react'

import StarterKit from '@tiptap/starter-kit'
Expand Down Expand Up @@ -35,15 +35,23 @@ export default function TextareaControl({
content: val,
editable: !disabled,
onUpdate: ({ editor }) => {
if (disabled) return
console.log('on update ')
onChange && !disabled && onChange(editor.getHTML())

const content = editor.getHTML()

onChange && onChange(content)
setValue(content)
}
})

useEffect(() => {
// setValue(value)
// value && editor?.commands.setContent(value)
}, [value, editor])
// it should be run as prop change
if (value !== val) {
setValue(value)
value && editor?.commands.setContent(value)
}
}, [value, editor, val])

useEffect(() => {
editor && editor.setEditable(!disabled)
Expand Down
16 changes: 9 additions & 7 deletions packages/ui-app/app/[orgID]/project/[projectId]/TaskUpdate2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ function TaskUpdateModal({
task: ITaskDefaultValues,
visible: boolean,
setVisible: () => void,
onSubmit: (v: ITaskDefaultValues) => void
onSubmit: (v: ITaskDefaultValues, cb: () => void) => void
}) {

console.log(task.desc)

return <Dialog.Root open={visible} onOpenChange={() => {
setVisible()
Expand Down Expand Up @@ -65,8 +66,6 @@ function useTaskIdChange(fn: (id: string) => void) {
const newUrl = new URL(window.location.toString())
const taskId = newUrl.searchParams.get('taskId')
if (taskId) {
console.log('FIRST TIME', taskId)
// setTaskId(taskId)
fn(taskId)
}

Expand Down Expand Up @@ -97,11 +96,9 @@ export const TaskUpdate2 = () => {

const closeTheModal = () => {
deleteState('taskId')
// closeTaskDetail()
// router.replace(`${orgID}/project/${projectId}?mode=${mode}`)
}

const handleSubmit = (v: ITaskDefaultValues) => {
const handleSubmit = (v: ITaskDefaultValues, cb: () => void) => {
if (!taskId) return

const dataUpdate = {
Expand All @@ -122,13 +119,18 @@ export const TaskUpdate2 = () => {
taskUpdate(dataUpdate)
.then(res => {
const { data, status } = res.data
if (status !== 200) return
if (status !== 200) {
cb()
return
}

messageSuccess('Synced success !')
syncRemoteTaskById(data.id, data as Task)
cb()
})
.catch(err => {
messageError('Update new task error')
cb()

if (!refCurrentTask.current) return
// syncRemoteTaskById(refCurrentTask.current.id, refCurrentTask.current)
Expand Down
21 changes: 5 additions & 16 deletions packages/ui-app/app/_features/TaskDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface ITaskFormProps {
taskStatusId?: string
dueDate?: Date
defaultValue?: ITaskDefaultValues
onSubmit: (v: ITaskDefaultValues) => void
onSubmit: (v: ITaskDefaultValues, cb: () => void) => void
}

export default function TaskDetail({
Expand Down Expand Up @@ -114,7 +114,10 @@ export default function TaskDetail({
return
}

onSubmit(mergedValues)
onSubmit(mergedValues, () => {
console.log('called')
})
setLoading(false)
}
})

Expand Down Expand Up @@ -277,20 +280,6 @@ export default function TaskDetail({
</div>
</div>
</div>
{/* <div className="task-info-item"> */}
{/* <div className="task-info-label"> */}
{/* <HiOutlineBattery50 /> <span>Progress</span> */}
{/* </div> */}
{/* <div className="task-info-content w-[230px] pl-3"> */}
{/* <Form.Range */}
{/* step={5} */}
{/* value={formik.values.progress} */}
{/* onChange={v => { */}
{/* formik.setFieldValue('progress', v) */}
{/* }} */}
{/* /> */}
{/* </div> */}
{/* </div> */}
<div className="flex flex-col items-start pt-2">
<div className="task-info-label">
<GoTasklist /> <span>Checklist</span>
Expand Down

0 comments on commit cedff71

Please sign in to comment.