UNPKG

@open-tender/cloud

Version:

A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our cloud-based Order API.

81 lines (80 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resetPasswordReducer = exports.selectResetPassword = exports.resetPasswordReset = exports.resetPassword = exports.sendPasswordResetEmail = exports.ResetPasswordActionType = void 0; const tslib_1 = require("tslib"); const toolkit_1 = require("@reduxjs/toolkit"); const types_1 = require("./types"); const initialState = { loading: 'idle', error: null, success: false, resetSent: false }; var ResetPasswordActionType; (function (ResetPasswordActionType) { ResetPasswordActionType["SendPasswordResetEmail"] = "resetPassword/sendPasswordResetEmail"; ResetPasswordActionType["ResetPassword"] = "resetPassword/resetPassword"; })(ResetPasswordActionType = exports.ResetPasswordActionType || (exports.ResetPasswordActionType = {})); exports.sendPasswordResetEmail = (0, toolkit_1.createAsyncThunk)(ResetPasswordActionType.SendPasswordResetEmail, ({ email, link_url }, { getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const { api } = getState().config; if (!api) return; try { yield api.postSendPasswordResetEmail(email, link_url); return; } catch (err) { return rejectWithValue(err); } })); exports.resetPassword = (0, toolkit_1.createAsyncThunk)(ResetPasswordActionType.ResetPassword, ({ new_password, resetToken }, { getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const { api } = getState().config; if (!api) return; try { yield api.postResetPassword(new_password, resetToken); return; } catch (err) { return rejectWithValue(err); } })); const resetPasswordSlice = (0, toolkit_1.createSlice)({ name: types_1.ReducerType.ResetPassword, initialState, reducers: { resetPasswordReset: () => initialState }, extraReducers: builder => { builder .addCase(exports.sendPasswordResetEmail.fulfilled, state => { state.resetSent = true; state.loading = 'idle'; state.error = null; }) .addCase(exports.sendPasswordResetEmail.pending, state => { state.loading = 'pending'; }) .addCase(exports.sendPasswordResetEmail.rejected, (state, action) => { state.loading = 'idle'; state.error = action.payload; }) .addCase(exports.resetPassword.fulfilled, state => { state.resetSent = false; state.success = true; state.loading = 'idle'; state.error = null; }) .addCase(exports.resetPassword.pending, state => { state.loading = 'pending'; }) .addCase(exports.resetPassword.rejected, (state, action) => { state.loading = 'idle'; state.error = action.payload; }); } }); exports.resetPasswordReset = resetPasswordSlice.actions.resetPasswordReset; const selectResetPassword = (state) => state.resetPassword; exports.selectResetPassword = selectResetPassword; exports.resetPasswordReducer = resetPasswordSlice.reducer;