Skip to content

Commit 8e460bf

Browse files
[#12]: fix error caused by New Entry
1 parent 6540858 commit 8e460bf

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

src/components/molecules/DeleteWorklogDialog.tsx

+32-22
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,42 @@ import { DestructiveButton } from '../atoms/Button'
44
import { ConfirmDialog } from './ConfirmDialog'
55

66
interface DeleteWorklogProps {
7-
open: boolean;
8-
onDelete: (updateOnly?: boolean) => Promise<void>;
9-
onClose: () => void;
7+
open: boolean
8+
onDelete: (updateOnly?: boolean) => Promise<void>
9+
onClose: () => void
1010
log: Worklog
1111
}
1212
export const DeleteWorklogDialog: React.FC<DeleteWorklogProps> = ({ open, onDelete, onClose, log }) => {
1313
const { data: options } = useOptions()
14-
const text = `Do you really want to ${!!log.id && !log.synced ? 'discard the changes for' : 'delete'} the worklog` +
14+
const text =
15+
`Do you really want to ${!!log.id && !log.synced ? 'discard the changes for' : 'delete'} the worklog` +
1516
` from ${timeString(log.start)} till ${timeString(log.end)} for Issue "${options.issues[log.issue.key]?.alias || log.issue.name}".`
16-
const buttons = !!log.id && !log.synced ? (
17-
<DestructiveButton onClick={() => {
18-
onClose()
19-
onDelete(true)
20-
}}>
21-
{!log.delete ? 'Discard Changes' : 'Undo Delete'}
22-
</DestructiveButton>
23-
) : (
24-
<DestructiveButton onClick={() => {
25-
onClose()
26-
onDelete()
27-
}}>Delete</DestructiveButton>
17+
const buttons =
18+
!!log.id && !log.synced ? (
19+
<DestructiveButton
20+
onClick={() => {
21+
onClose()
22+
onDelete(true)
23+
}}
24+
>
25+
{!log.delete ? 'Discard Changes' : 'Undo Delete'}
26+
</DestructiveButton>
27+
) : (
28+
<DestructiveButton
29+
onClick={() => {
30+
onClose()
31+
onDelete()
32+
}}
33+
>
34+
Delete
35+
</DestructiveButton>
36+
)
37+
return (
38+
<ConfirmDialog
39+
{...{ open, onDelete, onClose }}
40+
text={text}
41+
title={log.id && log.synced ? 'Confirm Deletion' : 'Confirm Discard'}
42+
buttons={buttons}
43+
/>
2844
)
29-
return <ConfirmDialog
30-
{...{ open, onDelete, onClose }}
31-
text={text}
32-
title={log.id && log.synced ? 'Confirm Deletion' : 'Confirm Discard'}
33-
buttons={buttons}
34-
/>
3545
}

src/components/views/Tracker.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ export const TrackerView: React.FC = () => {
7272
<H6 style={{ margin: '0 0 4px 8px', display: 'flex', width: 'calc(100% - 16px)' }}>
7373
<span style={{ marginRight: 'auto' }}>Tracking History</span>
7474
{!self.error && !hasUnsyncedLog && (
75-
<ActionLink
76-
disabled={!!editIssue.issue}
77-
style={{ marginRight: 4, lineHeight: '16px' }}
78-
onClick={() => worklog.forceFetch()}
79-
>
75+
<ActionLink disabled={!!editIssue.issue} style={{ marginRight: 4, lineHeight: '16px' }} onClick={() => worklog.forceFetch()}>
8076
Refresh
8177
</ActionLink>
8278
)}
@@ -89,15 +85,11 @@ export const TrackerView: React.FC = () => {
8985
Synchronize
9086
</ActionLink>
9187
)}
92-
<ActionLink
93-
disabled={!!editIssue.issue}
94-
style={{ marginRight: 4, lineHeight: '16px' }}
95-
onClick={() => setShowPeriodDialog(true)}
96-
>
88+
<ActionLink disabled={!!editIssue.issue} style={{ marginRight: 4, lineHeight: '16px' }} onClick={() => setShowPeriodDialog(true)}>
9789
Log Multiple
9890
</ActionLink>
9991
<ActionLink
100-
disabled={!!editIssue.issue}
92+
disabled={!!editIssue.issue || !createNewWorklog}
10193
style={{ marginRight: 4, lineHeight: '16px' }}
10294
onClick={createNewWorklog}
10395
>
@@ -111,9 +103,7 @@ export const TrackerView: React.FC = () => {
111103
{self.error && (
112104
<ErrorTooltipTop content={offlineTooltip}>
113105
<WifiOff
114-
onClick={() =>
115-
self.error === 'PERMISSION' && requestPermission(options).then(() => self.refetch())
116-
}
106+
onClick={() => self.error === 'PERMISSION' && requestPermission(options).then(() => self.refetch())}
117107
size={16}
118108
style={{
119109
color: 'var(--destructive)',

src/hooks/useInsertWorklog.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import { useDispatch, useSelector } from '../utils/atom'
44
import { useOptions } from './useOptions'
55
import { v4 } from 'uuid'
66
import { usePrevious } from './usePrevious'
7+
import { useJqlQueryResults } from './useJqlQueryResult'
78

89
export function useInsertWorklog () {
910
const dispatch = useDispatch()
1011
const editIssue = useSelector(editIssueDuck.selector)
12+
const remoteIssues = useJqlQueryResults() as LocalIssue[]
1113
const {data: options} = useOptions()
1214
const [newWorklog, setNewWorklog] = useState<TemporaryWorklog>(null)
1315
const previousIssue = usePrevious(editIssue.issue)
16+
const defaultIssue = Object.values(options.issues).concat(remoteIssues)[0]
1417

1518
const createNewWorklog = async () => {
16-
const issue = Object.values(options.issues)[0]
17-
const newLog: TemporaryWorklog = { issue, start: Date.now(), end: Date.now(), synced: false, tempId: v4() }
19+
const newLog: TemporaryWorklog = { issue: defaultIssue, start: Date.now(), end: Date.now(), synced: false, tempId: v4() }
1820
await dispatch('setEditIssue', { issue: newLog.tempId })
1921
setNewWorklog(newLog)
2022
}
@@ -27,6 +29,6 @@ export function useInsertWorklog () {
2729

2830
return {
2931
newWorklog,
30-
createNewWorklog
32+
createNewWorklog: defaultIssue ? createNewWorklog : undefined
3133
}
32-
}
34+
}

0 commit comments

Comments
 (0)