How to call another saga function from current saga function in same saga file?
I have 2 saga function in my saga handler file. *
function* fetchCustomDashboardCards - fetched the cards & saves cards in store
function* addPanelToCustomDashboard - adds a new card to customDashboard.
now I am invoking addPanelToCustomDashboard to add a card to dashboard, in which i make a api call to add the card. what i want here is, if my addPanelToCustomDashboard return success i want to call first saga fetchCustomDashboardCards to load the dashboard with newly added card. could someone tell me how would i call the another saga function from current saga function?
below is the code of both saga functions -
1st saga function -
export function* fetchCustomDashboardCards(action) {
const { botId } = action?.data;
const fetchCardsUrl = urlConfig.fetchCustomDashboardCardsUrl(botId);
try {
const { status, data } = yield call(() => api.get(fetchCardsUrl));
if (status === 200) {
//dispatch action to save cards of custom dashboard
} else {
//dispatch action saying some error occured while fetching cards
//remove this when apis start working
yield put(custom开发者_如何转开发DashboarCardsFetched({ cards: data?.cards }));
}
} catch (error) {
console.log('error occured while fetching custom dashboard cards');
//remove this when apis start working
yield put(customDashboarCardsFetched({ cards: [] }));
}
}
2nd saga function -
export function* addPanelToCustomDashboard(action) {
const { botId } = action?.data;
const addPanelUrl = urlConfig.addPanelToCustomDashboard(botId);
try {
const { status, data } = yield call(() =>
api.post(addPanelUrl, {
panelInfo: action?.data?.panelInfo
})
);
if (status === 200) {
***//ON SUCCESS RELOAD DASHBOARD WITH NEWLY ADDED CARD BY CALLING 1st SAGA FUNCTION***
} else {
//dispatch action saying some error occured
//remove this when apis start working
yield put(panelAddedToCustomDashboard({ panel: action?.data?.panelInfo }));
}
} catch (error) {
console.log('error occured while adding panel to custom dashboard');
//remove this when apis start working
yield put(panelAddedToCustomDashboard({ panel: action?.data?.panelInfo }));
}
}
精彩评论