mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-11 22:54:46 +08:00
Updating categories using form
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
AddBookmarkAction,
|
||||
PinCategoryAction,
|
||||
DeleteCategoryAction,
|
||||
UpdateCategoryAction,
|
||||
// Notifications
|
||||
CreateNotificationAction,
|
||||
ClearNotificationAction
|
||||
@@ -38,6 +39,7 @@ export enum ActionTypes {
|
||||
addBookmark = 'ADD_BOOKMARK',
|
||||
pinCategory = 'PIN_CATEGORY',
|
||||
deleteCategory = 'DELETE_CATEGORY',
|
||||
updateCategory = 'UPDATE_CATEGORY',
|
||||
// Notifications
|
||||
createNotification = 'CREATE_NOTIFICATION',
|
||||
clearNotification = 'CLEAR_NOTIFICATION'
|
||||
@@ -58,6 +60,7 @@ export type Action =
|
||||
AddBookmarkAction |
|
||||
PinCategoryAction |
|
||||
DeleteCategoryAction |
|
||||
UpdateCategoryAction |
|
||||
// Notifications
|
||||
CreateNotificationAction |
|
||||
ClearNotificationAction;
|
||||
@@ -147,4 +147,33 @@ export const deleteCategory = (id: number) => async (dispatch: Dispatch) => {
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UPDATE CATEGORY
|
||||
*/
|
||||
export interface UpdateCategoryAction {
|
||||
type: ActionTypes.updateCategory,
|
||||
payload: Category
|
||||
}
|
||||
|
||||
export const updateCategory = (id: number, formData: NewCategory) => async (dispatch: Dispatch) => {
|
||||
try {
|
||||
const res = await axios.put<ApiResponse<Category>>(`/api/categories/${id}`, formData);
|
||||
|
||||
dispatch<CreateNotificationAction>({
|
||||
type: ActionTypes.createNotification,
|
||||
payload: {
|
||||
title: 'Success',
|
||||
message: `Category ${formData.name} updated`
|
||||
}
|
||||
})
|
||||
|
||||
dispatch<UpdateCategoryAction>({
|
||||
type: ActionTypes.updateCategory,
|
||||
payload: res.data.data
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user