Skip to content

Commit b97a99d

Browse files
committed
fix: wpCourseware tasks fetching issue fixed
1 parent 41e1b62 commit b97a99d

File tree

5 files changed

+30
-81
lines changed

5 files changed

+30
-81
lines changed

frontend-dev/src/components/AllIntegrations/WPCourseware/WPCourseware.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Steps from '../../Utilities/Steps'
88
import { saveActionConf } from '../IntegrationHelpers/IntegrationHelpers'
99
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
1010
import WPCoursewareAuthorization from './WPCoursewareAuthorization'
11-
import { getWPCoursewareActions } from './WPCoursewareCommonFunc'
1211
import WPCoursewareIntegLayout from './WPCoursewareIntegLayout'
1312

1413
export default function WPCourseware({ formFields, setFlow, flow, allIntegURL }) {
@@ -27,9 +26,8 @@ export default function WPCourseware({ formFields, setFlow, flow, allIntegURL })
2726
actions: {}
2827
})
2928

30-
const nextPage = (val) => {
29+
const nextPage = val => {
3130
if (val === 2 && wpCoursewareConf.name !== '') {
32-
getWPCoursewareActions(wpCoursewareConf, setWPCoursewareConf)
3331
setStep(val)
3432
} else if (val === 3 && wpCoursewareConf.action !== '' && wpCoursewareConf.course.length > 0) {
3533
setStep(val)

frontend-dev/src/components/AllIntegrations/WPCourseware/WPCoursewareCommonFunc.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,24 @@
11
import toast from 'react-hot-toast'
22
import { __ } from '../../../Utils/i18nwrap'
33
import bitsFetch from '../../../Utils/bitsFetch'
4-
5-
export const getWPCoursewareActions = (wpCoursewareConf, setWPCoursewareConf) => {
6-
const response = bitsFetch({}, 'wpCourseware_actions')
7-
.then(result => {
8-
const newConf = { ...wpCoursewareConf }
9-
if (result.data.WPCWActions) {
10-
newConf.default.WPCWActions = result.data.WPCWActions
11-
}
12-
getWPCoursewareCourses(newConf, setWPCoursewareConf)
13-
})
14-
15-
toast.promise(response, {
16-
success: __('Action Refreshed', 'bit-integrations'),
17-
error: __('Failed, Try Again', 'bit-integrations'),
18-
loading: __('Fetching...'),
19-
})
20-
}
4+
import { create } from 'mutative'
215

226
export const getWPCoursewareCourses = (wpCoursewareConf, setWPCoursewareConf) => {
23-
const response = bitsFetch({}, 'wpCourseware_courses')
24-
.then(result => {
25-
const newConf = { ...wpCoursewareConf }
26-
if (result.data.WPCWCourses) {
27-
newConf.default.WPCWCourses = result.data.WPCWCourses
28-
}
29-
setWPCoursewareConf({ ...newConf })
30-
})
7+
const response = bitsFetch({}, 'wpCourseware_courses').then(result => {
8+
const newConf = { ...wpCoursewareConf }
9+
setWPCoursewareConf(prevConf =>
10+
create(prevConf, draftConf => {
11+
if (result.data.WPCWCourses) {
12+
draftConf.default.WPCWCourses = result.data.WPCWCourses
13+
}
14+
})
15+
)
16+
})
3117

3218
toast.promise(response, {
3319
success: __('Course Refreshed', 'bit-integrations'),
3420
error: __('Failed, Try Again', 'bit-integrations'),
35-
loading: __('Fetching...'),
21+
loading: __('Fetching...')
3622
})
3723
}
3824

frontend-dev/src/components/AllIntegrations/WPCourseware/WPCoursewareIntegLayout.jsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import MultiSelect from 'react-multiple-select-dropdown-lite'
33
import { __ } from '../../../Utils/i18nwrap'
44
import { getWPCoursewareCourses } from './WPCoursewareCommonFunc'
55
import Note from '../../Utilities/Note'
6+
import { create } from 'mutative'
67

78
export default function WPCoursewareIntegLayout({
89
wpCoursewareConf,
@@ -12,16 +13,22 @@ export default function WPCoursewareIntegLayout({
1213
setSnackbar
1314
}) {
1415
const inputHandler = ({ target: { name, value } }) => {
15-
setWPCoursewareConf({ ...wpCoursewareConf, [name]: value })
16+
setWPCoursewareConf(prevConf =>
17+
create(prevConf, draftConf => {
18+
draftConf[name] = value
19+
})
20+
)
21+
22+
getWPCoursewareCourses(wpCoursewareConf, setWPCoursewareConf, setIsLoading, setSnackbar)
1623
}
1724

18-
const setCourses = (val) => {
25+
const setCourses = val => {
1926
const newConf = { ...wpCoursewareConf }
2027

2128
if (val.includes('select_all_course')) {
2229
newConf.selectedAllCourse = wpCoursewareConf.default.WPCWCourses.filter(
23-
(course) => course.id !== 'select_all_course'
24-
).map((course) => course.id)
30+
course => course.id !== 'select_all_course'
31+
).map(course => course.id)
2532
} else {
2633
delete newConf.selectedAllCourse
2734
}
@@ -36,17 +43,13 @@ export default function WPCoursewareIntegLayout({
3643
<div className="flx">
3744
<b className="wdt-200 d-in-b">{__('WP Courseware Actions:', 'bit-integrations')}</b>
3845
<select
39-
onChange={(e) => inputHandler(e)}
46+
onChange={e => inputHandler(e)}
4047
name="action"
4148
value={wpCoursewareConf.action}
4249
className="btcd-paper-inp w-5">
4350
<option value="">{__('Select Action', 'bit-integrations')}</option>
44-
{wpCoursewareConf?.default?.WPCWActions &&
45-
Object.values(wpCoursewareConf.default.WPCWActions).map(({ id, title }) => (
46-
<option key={`${id}-1`} value={id}>
47-
{title}
48-
</option>
49-
))}
51+
<option value="enroll">{__('Enroll user in a Course', 'bit-integrations')}</option>
52+
<option value="unroll">{__('Unroll user in a Course', 'bit-integrations')}</option>
5053
</select>
5154
</div>
5255

@@ -63,16 +66,11 @@ export default function WPCoursewareIntegLayout({
6366
value: id.toString()
6467
}))
6568
}
66-
onChange={(val) => setCourses(val)}
69+
onChange={val => setCourses(val)}
6770
/>
6871
<button
6972
onClick={() =>
70-
getWPCoursewareCourses(
71-
wpCoursewareConf,
72-
setWPCoursewareConf,
73-
setIsLoading,
74-
setSnackbar
75-
)
73+
getWPCoursewareCourses(wpCoursewareConf, setWPCoursewareConf, setIsLoading, setSnackbar)
7674
}
7775
className="icn-btn sh-sm ml-2 mr-2 tooltip"
7876
style={{

includes/Actions/WPCourseware/Routes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
exit;
55
}
66

7-
use BitCode\FI\Actions\WPCourseware\WPCoursewareController;
87
use BitCode\FI\Core\Util\Route;
8+
use BitCode\FI\Actions\WPCourseware\WPCoursewareController;
99

1010
Route::post('wpCourseware_authorize', [WPCoursewareController::class, 'wpCoursewareAuthorize']);
11-
Route::post('wpCourseware_actions', [WPCoursewareController::class, 'WPCWActions']);
1211
Route::post('wpCourseware_courses', [WPCoursewareController::class, 'WPCWCourses']);

includes/Actions/WPCourseware/WPCoursewareController.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,6 @@ public static function wpCoursewareAuthorize()
2323
}
2424
}
2525

26-
public static function WPCWActions()
27-
{
28-
if (!is_plugin_active('wp-courseware/wp-courseware.php')) {
29-
wp_send_json_error(__('WP Courseware Plugin is not active or installed', 'bit-integrations'), 400);
30-
}
31-
32-
$actions = [];
33-
foreach (self::$actions as $action) {
34-
$actions[] = (object) [
35-
'id' => $action['id'],
36-
'title' => $action['title']
37-
];
38-
}
39-
40-
$response['WPCWActions'] = $actions;
41-
wp_send_json_success($response, 200);
42-
}
43-
4426
public static function WPCWCourses()
4527
{
4628
if (!is_plugin_active('wp-courseware/wp-courseware.php')) {
@@ -87,18 +69,4 @@ public function execute($integrationData, $fieldValues)
8769

8870
return $recordApiHelper->execute($action, $course, $userId, $allCourse);
8971
}
90-
91-
protected static function actions()
92-
{
93-
return [
94-
'enroll' => [
95-
'id' => 'enroll',
96-
'title' => __('Enroll user in a Course', 'bit-integrations')
97-
],
98-
'unroll' => [
99-
'id' => 'unroll',
100-
'title' => __('Unroll user in a Course', 'bit-integrations')
101-
],
102-
];
103-
}
10472
}

0 commit comments

Comments
 (0)