-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
62 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/api/action-groups/delete-yesterday-action-by-action-group-id.api.ts
This file contains 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,15 @@ | ||
import axios from 'axios' | ||
import { CustomizedAxiosResponse } from '../index.interface' | ||
import { GetActionGroupRes } from './index.interface' | ||
|
||
/** | ||
* Delete Yesterday's actions by action group id | ||
* this will delete EVERY yesterday's action. | ||
*/ | ||
export const deleteYesterdayActionsByActionGroupId = async ( | ||
actionGroupId: string, | ||
): Promise<CustomizedAxiosResponse<GetActionGroupRes>> => { | ||
const url = `/v1/action-groups/${actionGroupId}/actions/yesterday` | ||
const res = await axios.delete(url) | ||
return [res.data, res] | ||
} |
This file contains 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 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
37 changes: 37 additions & 0 deletions
37
src/hooks/action-group/use-delete-actions-by-action-group-id.hook.ts
This file contains 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,37 @@ | ||
import { useRecoilCallback } from 'recoil' | ||
import { useState } from 'react' | ||
import { actionGroupFamily } from '@/recoil/action-groups/action-groups.state' | ||
import { deleteTodayActionsByActionGroupId } from '@/api/action-groups/delete-today-actions-by-action-group-id.api' | ||
import { GetActionGroupRes } from '@/api/action-groups/index.interface' | ||
import { deleteYesterdayActionsByActionGroupId } from '@/api/action-groups/delete-yesterday-action-by-action-group-id.api' | ||
|
||
type UseDeleteActionsByActionGroupId = [boolean, () => Promise<void>] | ||
export const useDeleteActionsByActionGroupId = ( | ||
actionGroupId: string, | ||
which: 'today' | 'yesterday', // only two options | ||
): UseDeleteActionsByActionGroupId => { | ||
const [loading, setLoading] = useState(false) | ||
|
||
const onDeleteActionsByActionGroupId = useRecoilCallback( | ||
({ set }) => | ||
async () => { | ||
try { | ||
setLoading(true) | ||
let data: GetActionGroupRes | null = null | ||
if (which === `today`) { | ||
data = (await deleteTodayActionsByActionGroupId(actionGroupId))[0] | ||
} else { | ||
data = ( | ||
await deleteYesterdayActionsByActionGroupId(actionGroupId) | ||
)[0] | ||
} | ||
if (data === null) throw new Error(`data is null`) | ||
set(actionGroupFamily(data.props.id), data) | ||
} finally { | ||
setLoading(false) | ||
} | ||
}, | ||
[actionGroupId, which, setLoading], | ||
) | ||
return [loading, onDeleteActionsByActionGroupId] | ||
} |
26 changes: 0 additions & 26 deletions
26
src/hooks/action-group/use-delete-today-actions-by-action-group-id.hook.ts
This file was deleted.
Oops, something went wrong.