Skip to content

Commit

Permalink
Manual schedule fix
Browse files Browse the repository at this point in the history
npm build

Manual schedule
  • Loading branch information
alimuzzaman committed Aug 30, 2023
1 parent 754072c commit fda50a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
16 changes: 11 additions & 5 deletions includes/Admin/Settings/app/Settings/fields/ManualScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useBuilderContext } from 'quickbuilder';
import React, { useEffect, useMemo, useState } from 'react';
import Select from 'react-select';
import { SweetAlertStatusChangingMsg } from '../ToasterMsg';
import { convertTo12HourFormat, generateTimeOptions } from '../helper/helper';
import { convertTo12HourFormat, generateTimeOptions, isObject } from '../helper/helper';
import { selectStyles } from '../helper/styles';
import ProToggle from './utils/ProToggle';

Expand Down Expand Up @@ -42,10 +42,13 @@ const ManualScheduler = (props) => {
const handleSavedManualSchedule = () => {
setSavedManualSchedule( (prevSchedule) => {
const updatedSchedule = {weekdata: {}, ...prevSchedule};
if(!isObject(updatedSchedule.weekdata)){
updatedSchedule.weekdata = {};
}
// @ts-ignore
if( updatedSchedule?.weekdata?.[selectDay.value] ) {
if( !updatedSchedule?.weekdata?.[selectDay.value].includes(selectTime?.value) ){
updatedSchedule?.weekdata?.[selectDay.value].push( selectTime?.value );
if( updatedSchedule.weekdata[selectDay.value] ) {
if( !updatedSchedule.weekdata[selectDay.value].includes(selectTime?.value) ){
updatedSchedule.weekdata[selectDay.value].push( selectTime?.value );
}
}else{
updatedSchedule.weekdata[selectDay.value] = [selectTime?.value];
Expand All @@ -57,8 +60,11 @@ const ManualScheduler = (props) => {
const handleDeleteManualSchedule = ( item, data ) => {
setSavedManualSchedule( (prevSchedule) => {
const updatedSchedule = {weekdata: {}, ...prevSchedule};
if(!isObject(updatedSchedule.weekdata)){
updatedSchedule.weekdata = {};
}
// @ts-ignore
updatedSchedule?.weekdata?.[item.value] = updatedSchedule?.weekdata?.[item.value]?.filter( time => time !== data);
updatedSchedule.weekdata[item.value] = updatedSchedule.weekdata[item.value]?.filter( time => time !== data);
return updatedSchedule;
} );
}
Expand Down
14 changes: 9 additions & 5 deletions includes/Admin/Settings/app/Settings/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import apiFetch from '@wordpress/api-fetch';

// Fetch data from API
export const fetchDataFromAPI = async (body) => {
// @ts-ignore
// @ts-ignore
const ajax_url = wpspSettingsGlobal?.admin_ajax;
const response = await fetch(ajax_url, {
method: 'POST',
Expand Down Expand Up @@ -61,14 +61,14 @@ export const generateTabURL = () => {
// Send API request for fetch url
export const socialProfileRequestHandler = async (redirectURI, appID, appSecret, platform) => {
const data = {
action: 'wpsp_social_add_social_profile',
action: 'wpsp_social_add_social_profile',
redirectURI: redirectURI,
appId: appID,
appSecret: appSecret,
type: platform,
};
const response = await fetchDataFromAPI(data);

const responseData = await response.json();
if (responseData.success) {
open(responseData.data, '_self');
Expand Down Expand Up @@ -127,7 +127,7 @@ export const convertTo12HourFormat = (time24) => {
if ( !/\d{1,2}:\d{2} [ap]m/i.test(time24)) {
const [hours, minutes] = time24.split(':');
const isPM = parseInt(hours, 10) >= 12;

let hours12 = parseInt(hours, 10) % 12;
hours12 = hours12 === 0 ? 12 : hours12; // Handle midnight (00:00) as 12 AM
return `${hours12}:${minutes} ${isPM ? 'PM' : 'AM'}`;
Expand Down Expand Up @@ -193,4 +193,8 @@ export const findOptionLabelByValue = (data, targetValue) => {
}

return null;
}
}

export const isObject = (arg) => {
return arg !== null && typeof arg === 'object' && !Array.isArray(arg);
};
2 changes: 1 addition & 1 deletion includes/Admin/Settings/assets/js/admin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => 'f138b3b114a4e9e61f01');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => 'abab0ccbf8fa17e63b99');
2 changes: 1 addition & 1 deletion includes/Admin/Settings/assets/js/admin.js

Large diffs are not rendered by default.

0 comments on commit fda50a3

Please sign in to comment.