UNPKG

@woocommerce/data

Version:
497 lines (496 loc) 16.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.coreProfilerCompletedSuccess = exports.coreProfilerCompletedRequest = exports.coreProfilerCompletedError = exports.setJetpackAuthUrl = exports.installAndActivatePluginsAsync = exports.actionTask = exports.optimisticallyCompleteTask = exports.unhideTaskList = exports.hideTaskList = exports.undoDismissTask = exports.dismissTask = exports.undoSnoozeTask = exports.snoozeTask = exports.updateProfileItems = exports.keepCompletedTaskList = exports.getProductTypesError = exports.getProductTypesSuccess = exports.actionTaskSuccess = exports.actionTaskRequest = exports.actionTaskError = exports.setEmailPrefill = exports.setPaymentMethods = exports.visitedTask = exports.keepCompletedTaskListSuccess = exports.optimisticallyCompleteTaskRequest = exports.unhideTaskListSuccess = exports.unhideTaskListRequest = exports.unhideTaskListError = exports.hideTaskListSuccess = exports.hideTaskListRequest = exports.hideTaskListError = exports.undoDismissTaskSuccess = exports.undoDismissTaskRequest = exports.undoDismissTaskError = exports.dismissTaskSuccess = exports.dismissTaskRequest = exports.dismissTaskError = exports.undoSnoozeTaskSuccess = exports.undoSnoozeTaskRequest = exports.undoSnoozeTaskError = exports.snoozeTaskSuccess = exports.snoozeTaskRequest = exports.snoozeTaskError = exports.getTaskListsSuccess = exports.getTaskListsError = exports.setProfileItems = exports.setIsRequesting = exports.setError = exports.getFreeExtensionsSuccess = exports.getFreeExtensionsError = void 0; exports.coreProfilerCompleted = void 0; /** * External dependencies */ const data_controls_1 = require("@wordpress/data-controls"); const data_1 = require("@wordpress/data"); /** * Internal dependencies */ const action_types_1 = __importDefault(require("./action-types")); const constants_1 = require("../constants"); const deprecated_tasks_1 = require("./deprecated-tasks"); const constants_2 = require("../options/constants"); function getFreeExtensionsError(error) { return { type: action_types_1.default.GET_FREE_EXTENSIONS_ERROR, error, }; } exports.getFreeExtensionsError = getFreeExtensionsError; function getFreeExtensionsSuccess(freeExtensions) { return { type: action_types_1.default.GET_FREE_EXTENSIONS_SUCCESS, freeExtensions, }; } exports.getFreeExtensionsSuccess = getFreeExtensionsSuccess; function setError(selector, error) { return { type: action_types_1.default.SET_ERROR, selector, error, }; } exports.setError = setError; function setIsRequesting(selector, isRequesting) { return { type: action_types_1.default.SET_IS_REQUESTING, selector, isRequesting, }; } exports.setIsRequesting = setIsRequesting; function setProfileItems(profileItems, replace = false) { return { type: action_types_1.default.SET_PROFILE_ITEMS, profileItems, replace, }; } exports.setProfileItems = setProfileItems; function getTaskListsError(error) { return { type: action_types_1.default.GET_TASK_LISTS_ERROR, error, }; } exports.getTaskListsError = getTaskListsError; function getTaskListsSuccess(taskLists) { return { type: action_types_1.default.GET_TASK_LISTS_SUCCESS, taskLists, }; } exports.getTaskListsSuccess = getTaskListsSuccess; function snoozeTaskError(taskId, error) { return { type: action_types_1.default.SNOOZE_TASK_ERROR, taskId, error, }; } exports.snoozeTaskError = snoozeTaskError; function snoozeTaskRequest(taskId) { return { type: action_types_1.default.SNOOZE_TASK_REQUEST, taskId, }; } exports.snoozeTaskRequest = snoozeTaskRequest; function snoozeTaskSuccess(task) { return { type: action_types_1.default.SNOOZE_TASK_SUCCESS, task, }; } exports.snoozeTaskSuccess = snoozeTaskSuccess; function undoSnoozeTaskError(taskId, error) { return { type: action_types_1.default.UNDO_SNOOZE_TASK_ERROR, taskId, error, }; } exports.undoSnoozeTaskError = undoSnoozeTaskError; function undoSnoozeTaskRequest(taskId) { return { type: action_types_1.default.UNDO_SNOOZE_TASK_REQUEST, taskId, }; } exports.undoSnoozeTaskRequest = undoSnoozeTaskRequest; function undoSnoozeTaskSuccess(task) { return { type: action_types_1.default.UNDO_SNOOZE_TASK_SUCCESS, task, }; } exports.undoSnoozeTaskSuccess = undoSnoozeTaskSuccess; function dismissTaskError(taskId, error) { return { type: action_types_1.default.DISMISS_TASK_ERROR, taskId, error, }; } exports.dismissTaskError = dismissTaskError; function dismissTaskRequest(taskId) { return { type: action_types_1.default.DISMISS_TASK_REQUEST, taskId, }; } exports.dismissTaskRequest = dismissTaskRequest; function dismissTaskSuccess(task) { return { type: action_types_1.default.DISMISS_TASK_SUCCESS, task, }; } exports.dismissTaskSuccess = dismissTaskSuccess; function undoDismissTaskError(taskId, error) { return { type: action_types_1.default.UNDO_DISMISS_TASK_ERROR, taskId, error, }; } exports.undoDismissTaskError = undoDismissTaskError; function undoDismissTaskRequest(taskId) { return { type: action_types_1.default.UNDO_DISMISS_TASK_REQUEST, taskId, }; } exports.undoDismissTaskRequest = undoDismissTaskRequest; function undoDismissTaskSuccess(task) { return { type: action_types_1.default.UNDO_DISMISS_TASK_SUCCESS, task, }; } exports.undoDismissTaskSuccess = undoDismissTaskSuccess; function hideTaskListError(taskListId, error) { return { type: action_types_1.default.HIDE_TASK_LIST_ERROR, taskListId, error, }; } exports.hideTaskListError = hideTaskListError; function hideTaskListRequest(taskListId) { return { type: action_types_1.default.HIDE_TASK_LIST_REQUEST, taskListId, }; } exports.hideTaskListRequest = hideTaskListRequest; function hideTaskListSuccess(taskList) { return { type: action_types_1.default.HIDE_TASK_LIST_SUCCESS, taskList, taskListId: taskList.id, }; } exports.hideTaskListSuccess = hideTaskListSuccess; function unhideTaskListError(taskListId, error) { return { type: action_types_1.default.UNHIDE_TASK_LIST_ERROR, taskListId, error, }; } exports.unhideTaskListError = unhideTaskListError; function unhideTaskListRequest(taskListId) { return { type: action_types_1.default.UNHIDE_TASK_LIST_REQUEST, taskListId, }; } exports.unhideTaskListRequest = unhideTaskListRequest; function unhideTaskListSuccess(taskList) { return { type: action_types_1.default.UNHIDE_TASK_LIST_SUCCESS, taskList, taskListId: taskList.id, }; } exports.unhideTaskListSuccess = unhideTaskListSuccess; function optimisticallyCompleteTaskRequest(taskId) { return { type: action_types_1.default.OPTIMISTICALLY_COMPLETE_TASK_REQUEST, taskId, }; } exports.optimisticallyCompleteTaskRequest = optimisticallyCompleteTaskRequest; function keepCompletedTaskListSuccess(taskListId, keepCompletedList) { return { type: action_types_1.default.KEEP_COMPLETED_TASKS_SUCCESS, taskListId, keepCompletedTaskList: keepCompletedList, }; } exports.keepCompletedTaskListSuccess = keepCompletedTaskListSuccess; function visitedTask(taskId) { return { type: action_types_1.default.VISITED_TASK, taskId, }; } exports.visitedTask = visitedTask; function setPaymentMethods(paymentMethods) { return { type: action_types_1.default.GET_PAYMENT_METHODS_SUCCESS, paymentMethods, }; } exports.setPaymentMethods = setPaymentMethods; function setEmailPrefill(email) { return { type: action_types_1.default.SET_EMAIL_PREFILL, emailPrefill: email, }; } exports.setEmailPrefill = setEmailPrefill; function actionTaskError(taskId, error) { return { type: action_types_1.default.ACTION_TASK_ERROR, taskId, error, }; } exports.actionTaskError = actionTaskError; function actionTaskRequest(taskId) { return { type: action_types_1.default.ACTION_TASK_REQUEST, taskId, }; } exports.actionTaskRequest = actionTaskRequest; function actionTaskSuccess(task) { return { type: action_types_1.default.ACTION_TASK_SUCCESS, task, }; } exports.actionTaskSuccess = actionTaskSuccess; function getProductTypesSuccess(productTypes) { return { type: action_types_1.default.GET_PRODUCT_TYPES_SUCCESS, productTypes, }; } exports.getProductTypesSuccess = getProductTypesSuccess; function getProductTypesError(error) { return { type: action_types_1.default.GET_PRODUCT_TYPES_ERROR, error, }; } exports.getProductTypesError = getProductTypesError; function* keepCompletedTaskList(taskListId) { const updateOptionsParams = { woocommerce_task_list_keep_completed: 'yes', }; const response = yield data_1.controls.dispatch(constants_2.STORE_NAME, 'updateOptions', updateOptionsParams); if (response && response.success) { yield keepCompletedTaskListSuccess(taskListId, 'yes'); } } exports.keepCompletedTaskList = keepCompletedTaskList; function* updateProfileItems(items) { yield setIsRequesting('updateProfileItems', true); yield setError('updateProfileItems', null); try { const results = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/profile`, method: 'POST', data: items, }); if (results && results.status === 'success') { yield setProfileItems(items); yield setIsRequesting('updateProfileItems', false); return results; } throw new Error(); } catch (error) { yield setError('updateProfileItems', error); yield setIsRequesting('updateProfileItems', false); throw error; } } exports.updateProfileItems = updateProfileItems; function* snoozeTask(id) { yield snoozeTaskRequest(id); try { const task = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/snooze`, method: 'POST', }); yield snoozeTaskSuccess(deprecated_tasks_1.DeprecatedTasks.possiblyPruneTaskData(task, [ 'isSnoozed', 'isDismissed', 'snoozedUntil', ])); } catch (error) { yield snoozeTaskError(id, error); throw new Error(); } } exports.snoozeTask = snoozeTask; function* undoSnoozeTask(id) { yield undoSnoozeTaskRequest(id); try { const task = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/undo_snooze`, method: 'POST', }); yield undoSnoozeTaskSuccess(deprecated_tasks_1.DeprecatedTasks.possiblyPruneTaskData(task, [ 'isSnoozed', 'isDismissed', 'snoozedUntil', ])); } catch (error) { yield undoSnoozeTaskError(id, error); throw new Error(); } } exports.undoSnoozeTask = undoSnoozeTask; function* dismissTask(id) { yield dismissTaskRequest(id); try { const task = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/dismiss`, method: 'POST', }); yield dismissTaskSuccess(deprecated_tasks_1.DeprecatedTasks.possiblyPruneTaskData(task, [ 'isDismissed', 'isSnoozed', ])); } catch (error) { yield dismissTaskError(id, error); throw new Error(); } } exports.dismissTask = dismissTask; function* undoDismissTask(id) { yield undoDismissTaskRequest(id); try { const task = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/undo_dismiss`, method: 'POST', }); yield undoDismissTaskSuccess(deprecated_tasks_1.DeprecatedTasks.possiblyPruneTaskData(task, [ 'isDismissed', 'isSnoozed', ])); } catch (error) { yield undoDismissTaskError(id, error); throw new Error(); } } exports.undoDismissTask = undoDismissTask; function* hideTaskList(id) { yield hideTaskListRequest(id); try { const taskList = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/hide`, method: 'POST', }); yield hideTaskListSuccess(taskList); } catch (error) { yield hideTaskListError(id, error); throw new Error(); } } exports.hideTaskList = hideTaskList; function* unhideTaskList(id) { yield unhideTaskListRequest(id); try { const taskList = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/unhide`, method: 'POST', }); yield unhideTaskListSuccess(taskList); } catch (error) { yield unhideTaskListError(id, error); throw new Error(); } } exports.unhideTaskList = unhideTaskList; function* optimisticallyCompleteTask(id) { yield optimisticallyCompleteTaskRequest(id); } exports.optimisticallyCompleteTask = optimisticallyCompleteTask; function* actionTask(id) { yield actionTaskRequest(id); try { const task = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/tasks/${id}/action`, method: 'POST', }); yield actionTaskSuccess(deprecated_tasks_1.DeprecatedTasks.possiblyPruneTaskData(task, ['isActioned'])); } catch (error) { yield actionTaskError(id, error); throw new Error(); } } exports.actionTask = actionTask; function* installAndActivatePluginsAsync(plugins) { yield setIsRequesting('installAndActivatePluginsAsync', true); try { const results = yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/onboarding/plugins/install-and-activate-async`, method: 'POST', data: { plugins }, }); return results; } catch (error) { throw error; } finally { yield setIsRequesting('installAndActivatePluginsAsync', false); } } exports.installAndActivatePluginsAsync = installAndActivatePluginsAsync; function setJetpackAuthUrl(results, redirectUrl, from = '') { return { type: action_types_1.default.SET_JETPACK_AUTH_URL, results, redirectUrl, from, }; } exports.setJetpackAuthUrl = setJetpackAuthUrl; function coreProfilerCompletedError(error) { return { type: action_types_1.default.CORE_PROFILER_COMPLETED_ERROR, error, }; } exports.coreProfilerCompletedError = coreProfilerCompletedError; function coreProfilerCompletedRequest() { return { type: action_types_1.default.CORE_PROFILER_COMPLETED_REQUEST, }; } exports.coreProfilerCompletedRequest = coreProfilerCompletedRequest; function coreProfilerCompletedSuccess() { return { type: action_types_1.default.CORE_PROFILER_COMPLETED_SUCCESS, }; } exports.coreProfilerCompletedSuccess = coreProfilerCompletedSuccess; function* coreProfilerCompleted() { yield coreProfilerCompletedRequest(); try { yield (0, data_controls_1.apiFetch)({ path: `${constants_1.WC_ADMIN_NAMESPACE}/launch-your-store/initialize-coming-soon`, method: 'POST', }); } catch (error) { yield coreProfilerCompletedError(error); throw error; } finally { yield coreProfilerCompletedSuccess(); } } exports.coreProfilerCompleted = coreProfilerCompleted;