-
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
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
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
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,28 @@ | ||
import { axiosInstance, handleApiError } from '../api' | ||
|
||
export const fetchFolders = async () => { | ||
try { | ||
const { data } = await axiosInstance.get('/folders') | ||
return data | ||
} catch (error) { | ||
return handleApiError(error) | ||
} | ||
} | ||
|
||
export const createFolder = async (folderName: string) => { | ||
try { | ||
const { data } = await axiosInstance.post('/folders', { folderName }) | ||
return data | ||
} catch (error) { | ||
return handleApiError(error) | ||
} | ||
} | ||
|
||
export const deleteFolder = async (folderId: number) => { | ||
try { | ||
await axiosInstance.delete(`/folders/${folderId}`) | ||
return { success: true } | ||
} catch (error) { | ||
return handleApiError(error) | ||
} | ||
} |
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,26 @@ | ||
import { createFolder, deleteFolder, fetchFolders } from '@services/folder' | ||
import { AppDispatch } from '@store/store' | ||
import { addFolder, removeFolder, setFolders } from '@store/slices' | ||
|
||
export const performFetchFolders = () => async (dispatch: AppDispatch) => { | ||
const folders = await fetchFolders() | ||
if (folders) { | ||
dispatch(setFolders(folders)) | ||
} | ||
} | ||
|
||
export const performCreateFolder = | ||
(folderName: string) => async (dispatch: AppDispatch) => { | ||
const newFolder = await createFolder(folderName) | ||
if (newFolder) { | ||
dispatch(addFolder(newFolder)) | ||
} | ||
} | ||
|
||
export const performDeleteFolder = | ||
(folderId: number) => async (dispatch: AppDispatch) => { | ||
const result = await deleteFolder(folderId) | ||
if (result.success) { | ||
dispatch(removeFolder(folderId)) | ||
} | ||
} |
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,5 @@ | ||
export { | ||
performFetchFolders, | ||
performCreateFolder, | ||
performDeleteFolder, | ||
} from './folder' |
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