Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 110 additions & 60 deletions src/store/actions/indActivities.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
/* eslint-disable */

import { toast } from 'react-toastify';
import Swal from 'sweetalert2';
import { toast } from "react-toastify";
import Swal from "sweetalert2";

import resourceService from 'services/resource.service';
import indResourceService from 'services/indActivities.service';
import store from '../index';
import * as actionTypes from '../actionTypes';
import resourceService from "services/resource.service";
import indResourceService from "services/indActivities.service";
import store from "../index";
import * as actionTypes from "../actionTypes";

export const createIndResourceAction = (metadata, hide, accountId, settingId, redirecttoactivity, fullWidth) => async (dispatch) => {
export const createIndResourceAction = (
metadata,
hide,
accountId,
settingId,
redirecttoactivity,
fullWidth
) => async (dispatch) => {
const centralizedState = store.getState();
const {
organization: { activeOrganization },
} = centralizedState;
const data = {
library: window.h5peditorCopy.getLibrary(),
parameters: JSON.stringify(window.h5peditorCopy.getParams()),
action: 'create',
action: "create",
brightcove_account_id: accountId || undefined,
brightcove_api_setting_id: settingId || undefined,
};
toast.info('Creating new Activity ...', {
className: 'project-loading',
toast.info("Creating new Activity ...", {
className: "project-loading",
closeOnClick: false,
closeButton: false,
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 100000,
icon: '',
icon: "",
});
const insertedH5pResource = await resourceService.h5pToken(data);
if (!insertedH5pResource.fail) {
Expand All @@ -35,10 +42,10 @@ export const createIndResourceAction = (metadata, hide, accountId, settingId, re
const activity = {
h5p_content_id: resource.id,
thumb_url: metadata?.thumb_url,
action: 'create',
action: "create",
title: metadata?.title,
type: 'h5p',
content: 'place_holder',
type: "h5p",
content: "place_holder",
subject_id: metadata?.subject_id,
education_level_id: metadata?.education_level_id,
author_tag_id: metadata?.author_tag_id,
Expand All @@ -48,39 +55,44 @@ export const createIndResourceAction = (metadata, hide, accountId, settingId, re
organization_visibility_type_id: 1,
};

const result = await indResourceService.create(activeOrganization.id, activity);
const resultShared = await indResourceService.sharedIndependentActivity(insertedH5pResource.id);
window.top.postMessage(resultShared, 'http://127.0.0.1:5501');
const result = await indResourceService.create(
activeOrganization.id,
activity
);
const resultShared = await indResourceService.sharedIndependentActivity(
insertedH5pResource.id
);
window.top.postMessage(resultShared, "http://127.0.0.1:5501");
toast.dismiss();
toast.success('Activity Created', {
toast.success("Activity Created", {
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 4000,
});

if (fullWidth) {
setTimeout(() => {
Swal.fire({
title: 'We can close the window here now',
title: "We can close the window here now",
showConfirmButton: false,
showCancelButton: false,
});
}, [1500]);
} else {
dispatch({
type: actionTypes.ADD_IND_ACTIVITIES,
payload: result['independent-activity'],
payload: result["independent-activity"],
});
hide();
dispatch({
type: actionTypes.SET_ACTIVE_ACTIVITY_SCREEN,
payload: '',
payload: "",
});
dispatch({
type: 'ADD_VIDEO_URL',
payload: '',
type: "ADD_VIDEO_URL",
payload: "",
});
if (redirecttoactivity) {
window.location.href = '/';
window.location.href = "/";
}
}
}
Expand All @@ -100,11 +112,18 @@ export const createIndResourceAction = (metadata, hide, accountId, settingId, re
// });
// }
// };
export const allIndActivity = (orgId, page, size, search) => async (dispatch) => {
export const allIndActivity = (orgId, page, size, search) => async (
dispatch
) => {
dispatch({
type: actionTypes.ALL_IND_ACTIVITIES_REQUEST,
});
const allActivities = await indResourceService.allIndActivity(orgId, page, size, search);
const allActivities = await indResourceService.allIndActivity(
orgId,
page,
size,
search
);
// console.log("allActivities", allActivities);
if (allActivities) {
if (page > 1) {
Expand All @@ -130,8 +149,22 @@ export const allIndActivity = (orgId, page, size, search) => async (dispatch) =>
return allActivities;
};

export const allAdminExportActivity = (orgId, page, size, search, column, orderBy) => async (dispatch) => {
const allActivities = await indResourceService.allAdminExportActivity(orgId, page, size, search, column, orderBy);
export const allAdminExportActivity = (
orgId,
page,
size,
search,
column,
orderBy
) => async (dispatch) => {
const allActivities = await indResourceService.allAdminExportActivity(
orgId,
page,
size,
search,
column,
orderBy
);
// console.log("allActivities", allActivities);
if (allActivities) {
dispatch({
Expand All @@ -146,15 +179,20 @@ export const allAdminExportActivity = (orgId, page, size, search, column, orderB
}
};

export const deleteIndActivity = (activityId, admin) => async (dispatch) => {
export const deleteIndActivity = (activityId, admin) => async (
dispatch
) => {
const centralizedState = store.getState();
const {
organization: { activeOrganization },
} = centralizedState;
const allActivities = await indResourceService.deleteIndActivity(activeOrganization.id, activityId);
const allActivities = await indResourceService.deleteIndActivity(
activeOrganization.id,
activityId
);
if (allActivities.message) {
Swal.fire({
icon: 'success',
icon: "success",
html: allActivities.message,
});
if (admin) {
Expand All @@ -171,36 +209,44 @@ export const deleteIndActivity = (activityId, admin) => async (dispatch) => {
}
};

export const editIndActivityItem = (activityId, data, admin) => async (dispatch) => {
export const editIndActivityItem = (
activityId,
data,
admin
) => async (dispatch) => {
const centralizedState = store.getState();
const {
organization: { activeOrganization },
} = centralizedState;
toast.info('Updating Activity ...', {
className: 'project-loading',
toast.info("Updating Activity ...", {
className: "project-loading",
closeOnClick: false,
closeButton: false,
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 100000,
icon: '',
icon: "",
});

const editActivities = await indResourceService.editIndActivityItem(activeOrganization.id, data, activityId);
const editActivities = await indResourceService.editIndActivityItem(
activeOrganization.id,
data,
activityId
);
toast.dismiss();
toast.success('Activity Updated', {
toast.success("Activity Updated", {
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 4000,
});
if (editActivities) {
if (admin) {
dispatch({
type: actionTypes.EDIT_ADMIN_IND_ACTIVITIES,
payload: editActivities['independent-activity'],
payload: editActivities["independent-activity"],
});
} else {
dispatch({
type: actionTypes.EDIT_IND_ACTIVITIES,
payload: editActivities['independent-activity'],
payload: editActivities["independent-activity"],
});
}
}
Expand All @@ -211,15 +257,15 @@ export const adminIntActivities = (
page,
size,
searchQueryProject,
column = '',
orderBy = '',
column = "",
orderBy = "",
authorId,
createdFrom,
createdTo,
updatedFrom,
updatedTo,
shared,
index,
index
) => async (dispatch) => {
const allActivities = await indResourceService.allAdminIntActivities(
orgId,
Expand All @@ -234,7 +280,7 @@ export const adminIntActivities = (
updatedFrom,
updatedTo,
shared,
index,
index
);
if (allActivities) {
dispatch({
Expand All @@ -249,78 +295,82 @@ export const adminIntActivities = (
}
};
export const shareEnableLink = (id, admin) => async (dispatch) => {
toast.info('Updating Activity ...', {
className: 'project-loading',
toast.info("Exporting Activity ...", {
className: "project-loading",
closeOnClick: false,
closeButton: false,
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 100000,
icon: '',
icon: "",
});
const result = await indResourceService.shareEnable(id);
toast.dismiss();
toast.success('Activity Updated', {
toast.success("Activity (xApi) is downloaded", {
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 4000,
});
if (admin) {
dispatch({
type: actionTypes.EDIT_ADMIN_IND_ACTIVITIES,
payload: result?.['independent-activity'],
payload: result?.["independent-activity"],
});
} else {
dispatch({
type: actionTypes.EDIT_IND_ACTIVITIES,
payload: result['independent-activity'],
payload: result["independent-activity"],
});
}
return result;
};
export const shareDisableLink = (id, admin) => async (dispatch) => {
toast.info('Updating Activity ...', {
className: 'project-loading',
toast.info("Updating Activity ...", {
className: "project-loading",
closeOnClick: false,
closeButton: false,
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 100000,
icon: '',
icon: "",
});
const result = await indResourceService.shareDisable(id);
toast.dismiss();
toast.success('Activity Updated', {
toast.success("Activity Updated", {
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 4000,
});
if (admin) {
dispatch({
type: actionTypes.EDIT_ADMIN_IND_ACTIVITIES,
payload: result?.['independent-activity'],
payload: result?.["independent-activity"],
});
} else {
dispatch({
type: actionTypes.EDIT_IND_ACTIVITIES,
payload: result['independent-activity'],
payload: result["independent-activity"],
});
}
return result;
};

export const getIndex = (id, index, admin) => async (dispatch) => {
toast.info('Updating Activity ...', {
className: 'project-loading',
toast.info("Updating Activity ...", {
className: "project-loading",
closeOnClick: false,
closeButton: false,
position: toast.POSITION.BOTTOM_RIGHT,
autoClose: 100000,
icon: '',
icon: "",
});
let result;
if (admin) {
result = await indResourceService.getIndex(id, index.indexing, admin);
result = await indResourceService.getIndex(
id,
index.indexing,
admin
);
} else {
result = await indResourceService.getIndex(id, index);
}
console.log('Reslt index', result);
console.log("Reslt index", result);
toast.dismiss();

if (result.message) {
Expand Down