Skip to content

Commit

Permalink
4908 rules meta info update
Browse files Browse the repository at this point in the history
  • Loading branch information
remizov-arena committed Aug 26, 2024
1 parent f431300 commit d71d099
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions smart-frontend/app/src/store/adh/rules/rulesActionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,30 @@ const stopRule = createAsyncThunk('adh/rulesActions/stopRule', async (ruleId: nu
}
});

const withFullUpdate = (name: string, dialogAction: ReturnType<typeof createAsyncThunk>) => {
type DialogActionType = ReturnType<typeof createAsyncThunk>;

const withFullUpdate = (name: string, dialogAction: DialogActionType) => {
return createAsyncThunk(name, async (payload: unknown, thunkAPI) => {
await thunkAPI.dispatch(dialogAction(payload)).unwrap();
thunkAPI.dispatch(getRulesMetaInfo());
thunkAPI.dispatch(getRules());
});
};

const withMetaInfoUpdate = (name: string, dialogAction: ReturnType<typeof createAsyncThunk>) => {
const withMetaInfoUpdate = (name: string, dialogAction: DialogActionType) => {
return createAsyncThunk(name, async (payload: unknown, thunkAPI) => {
await thunkAPI.dispatch(dialogAction(payload)).unwrap();
thunkAPI.dispatch(getRulesMetaInfo());
});
};

const createRuleWithUpdate = withFullUpdate(
'adh/rulesActions/createRuleWithUpdate',
createRule as ReturnType<typeof createAsyncThunk>,
);

const deleteRuleWithUpdate = withFullUpdate(
'adh/rulesActions/deleteRuleWithUpdate',
deleteRule as ReturnType<typeof createAsyncThunk>,
);

const startRuleWithUpdate = withMetaInfoUpdate(
'adh/rulesActions/startRuleWithUpdate',
startRule as ReturnType<typeof createAsyncThunk>,
);

const stopRuleWithUpdate = withMetaInfoUpdate(
'adh/rulesActions/stopRuleWithUpdate',
stopRule as ReturnType<typeof createAsyncThunk>,
);
const createRuleWithUpdate = withFullUpdate('adh/rulesActions/createRuleWithUpdate', createRule as DialogActionType);

const deleteRuleWithUpdate = withFullUpdate('adh/rulesActions/deleteRuleWithUpdate', deleteRule as DialogActionType);

const startRuleWithUpdate = withMetaInfoUpdate('adh/rulesActions/startRuleWithUpdate', startRule as DialogActionType);

const stopRuleWithUpdate = withMetaInfoUpdate('adh/rulesActions/stopRuleWithUpdate', stopRule as DialogActionType);

interface AdhRulesActions extends ModalState<AdhRule, 'rule'> {
startDialog: {
Expand Down

0 comments on commit d71d099

Please sign in to comment.