Skip to content

Commit

Permalink
Fixed: OLD License Code
Browse files Browse the repository at this point in the history
  • Loading branch information
priyomukul committed Nov 28, 2023
1 parent 3f2d27c commit 375100e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 171 deletions.
230 changes: 80 additions & 150 deletions includes/Admin/Settings/app/Settings/fields/License.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { __ } from '@wordpress/i18n';
import classNames from 'classnames';
import React, { useEffect, useState } from 'react';
import { SweetAlertToaster } from '../ToasterMsg';
import { activateLicense, deActivateLicense, getLicense, resendOtp, sendOpt } from '../helper/helper';
import Verification from './utils/Verification';
import { activateLicense, deActivateLicense, getLicense } from '../helper/helper';
function License(props) {
const [inputChanged, setInputChanged] = useState(false)
const [tempKey, setTempKey] = useState(
Expand All @@ -13,49 +12,44 @@ function License(props) {
if (!localStorage.getItem('wpsp_is_valid')) {
getLicense( {} ).then( (response) => {
// @ts-ignore
localStorage.setItem('wpsp_is_valid', response?.status)
localStorage.setItem('wpsp_is_valid', response?.data.status)
// @ts-ignore
localStorage.setItem('wpsp_temp_key', response?.key)
localStorage.setItem('wpsp_temp_key', response?.data.key)
// @ts-ignore
setValid(response?.status)
setValid(response?.data.status)
// @ts-ignore
setTempKey(response?.key)
setTempKey(response?.data.key)
} )
}
}, [])

const [valid, setValid] = useState(localStorage.getItem('wpsp_is_valid'))
const [isRequestSend, setIsRequestSend] = useState(null)
const [isSendingVerificationRequest, setIsSendingVerificationRequest] = useState(false);
const [isSendingResendRequest, setIsSendingResendRequest] = useState(false);
const [isRequiredOtp,setIsRequiredOtp] = useState('');
const [validLicense,setValidLicense] = useState('');
const [email,setEmail] = useState('');
const [isSedingActivationRequest,setIsSedingActivationRequest] = useState(false);

const handleLicenseActivation = () => {
setIsRequestSend(true)
setIsSedingActivationRequest(true);
let data = {
license_key: tempKey,
key: tempKey,
}
setIsRequestSend(null)
setInputChanged(false)
activateLicense( data ).then( ( response ) => {
setIsSedingActivationRequest(false);
setIsRequestSend(null)
setInputChanged(false)
// @ts-ignore
if (response.success === true) {
// @ts-ignore
setIsRequiredOtp(response?.license)
// @ts-ignore
setEmail( response?.customer_email );
// @ts-ignore
setValidLicense(tempKey);
localStorage.setItem('wpsp_is_valid', response?.data.status)
// @ts-ignore
localStorage.setItem('wpsp_temp_key', response?.data.key)
// @ts-ignore
setTempKey(response.data.key)
// @ts-ignore
setValid(response.data.status)
SweetAlertToaster();
SweetAlertToaster({
type : 'info',
title : __( 'Please validate OTP.', 'wp-scheduled-posts' ),
type : 'success',
title : __( 'Your License is Successfully Activated.', 'wp-scheduled-posts' ),
}).fire();
} else {
// @ts-ignore
Expand All @@ -66,10 +60,9 @@ function License(props) {
}).fire();
}
} ).catch( (error) => {
setIsSedingActivationRequest(false);
SweetAlertToaster({
type : 'error',
title : __( error.message, 'wp-scheduled-posts' ),
title : __( error, 'wp-scheduled-posts' ),
}).fire();
} );
}
Expand All @@ -84,7 +77,7 @@ function License(props) {
localStorage.removeItem('wpsp_is_valid')
localStorage.removeItem('wpsp_temp_key')
// @ts-ignore
setValid(response?.license)
setValid(response.data.status)
setTempKey('')
SweetAlertToaster({
type : 'success',
Expand All @@ -95,142 +88,79 @@ function License(props) {
let response_data = response.data;
SweetAlertToaster({
type : 'error',
title : __( `${response_data}`, 'wp-scheduled-posts' ),
title : __( response_data, 'wp-scheduled-posts' ),
}).fire();
}
} ).catch( (error) => {
setIsRequestSend(null)
SweetAlertToaster({
type : 'error',
title : __( error?.message, 'wp-scheduled-posts' ),
title : __( error, 'wp-scheduled-posts' ),
}).fire();
} );
}

// Handle opt verification
const handleOtpVerification = (getOtp) => {
let data = {
otp: getOtp,
license: validLicense,
license_key: validLicense,
}
setIsSendingVerificationRequest(true);
sendOpt( data ).then( ( response ) => {
setIsSendingVerificationRequest(false);
// @ts-ignore
localStorage.setItem('wpsp_is_valid', response?.license)
// @ts-ignore
localStorage.setItem('wpsp_temp_key', response?.license_key)
// @ts-ignore
// setTempKey(response.key)
setTempKey(response?.license_key)
// @ts-ignore
setIsRequiredOtp(response?.license)
// @ts-ignore
setValid(response?.license)
SweetAlertToaster({
type : 'success',
title : __( 'Your License is Successfully Activated.', 'wp-scheduled-posts' ),
}).fire();
} ).catch( (error) => {
setIsSendingVerificationRequest(false);
SweetAlertToaster({
type : 'error',
title : __( error.message, 'wp-scheduled-posts' ),
}).fire();
} );
}

const handleResendOtp = () => {
let data = {
license_key: validLicense,
license: validLicense,
}
setIsSendingResendRequest(true);
resendOtp( data ).then( ( response ) => {
setIsSendingResendRequest(false);
// @ts-ignore
setIsRequiredOtp(response?.license)
// @ts-ignore
setValidLicense(tempKey);
SweetAlertToaster({
type : 'success',
title : __( 'Your OTP has been sended again Successfully!!.', 'wp-scheduled-posts' ),
}).fire();
} ).catch( (error) => {
setIsSendingResendRequest(true);
SweetAlertToaster({
type : 'error',
title : __( error.message, 'wp-scheduled-posts' ),
}).fire();
} );
}

return (
<div className={classNames('wprf-control', 'wprf-license', `wprf-${props.name}-social-profile`, props?.classes)}>
<div className='wpsp-license-container-2'>
<h4>{props?.label}</h4>
<div className='wpsp-license-key-wrapper'>
<div className='wpsp-license-input'>
{tempKey && valid == 'valid' ? (
<input
id='wp-scheduled-posts-pro-license-key'
className='activated'
placeholder='Place Your License Key and Activate'
onChange={(e) => setTempKey(e.target.value)}
value={tempKey}
disabled={true}
/>
) : (
<input
id='wp-scheduled-posts-pro-license-key'
placeholder='Place Your License Key and Activate'
onChange={(e) => setTempKey(e.target.value)}
value={ tempKey ? tempKey : ''}
/>
)}
</div>
<div className='wpsp-license-buttons'>
{valid == 'valid' ? (
<button
id='submit'
type='button'
className={
inputChanged
? 'wpsp-license-deactivation-btn changed'
: 'wpsp-license-deactivation-btn'
}
onClick={() => handleLicenseDeactivation()}
>
{isRequestSend == true
? 'Request Sending...'
: 'Deactivate License'}
</button>
) : (
<button
id='submit'
type='button'
className={
inputChanged
? 'wpsp-license-buttons changed'
: 'wpsp-license-buttons'
}
onClick={() => handleLicenseActivation()}
disabled={!tempKey}
>
{isSedingActivationRequest == true
? 'Request Sending...'
: 'Activate License'}
</button>
)}
return (
<div className={classNames('wprf-control', 'wprf-license', `wprf-${props.name}-social-profile`, props?.classes)}>
<div className='wpsp-license-container-2'>
<h4>{props?.label}</h4>
<div className='wpsp-license-key-wrapper'>
<div className='wpsp-license-input'>
{tempKey && valid == 'valid' ? (
<input
id='wp-scheduled-posts-pro-license-key'
className='activated'
placeholder='Place Your License Key and Activate'
onChange={(e) => setTempKey(e.target.value)}
value={tempKey}
disabled={true}
/>
) : (
<input
id='wp-scheduled-posts-pro-license-key'
placeholder='Place Your License Key and Activate'
onChange={(e) => setTempKey(e.target.value)}
value={ tempKey ? tempKey : ''}
/>
)}
</div>
<div className='wpsp-license-buttons'>
{valid == 'valid' ? (
<button
id='submit'
type='button'
className={
inputChanged
? 'wpsp-license-deactivation-btn changed'
: 'wpsp-license-deactivation-btn'
}
onClick={() => handleLicenseDeactivation()}
>
{isRequestSend == true
? 'Request Sending...'
: 'Deactivate License'}
</button>
) : (
<button
id='submit'
type='button'
className={
inputChanged
? 'wpsp-license-buttons changed'
: 'wpsp-license-buttons'
}
onClick={() => handleLicenseActivation()}
disabled={!tempKey}
>
{isRequestSend == true
? 'Request Sending...'
: 'Activate License'}
</button>
)}
</div>
</div>
</div>
</div>
{ isRequiredOtp === 'required_otp' &&
<Verification email={email} submitOTP={ handleOtpVerification } resendOTP={ handleResendOtp } isRequestSending={ isSendingVerificationRequest } isSendingResendRequest={isSendingResendRequest} />
}
</div>
)
)
}

export default License
export default License
24 changes: 3 additions & 21 deletions includes/Admin/Settings/app/Settings/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,18 @@ export const fetPinterestBoardData = async (body) => {

export const activateLicense = async (body) => {
return apiFetch( {
path: 'wp-scheduled-posts/v1/license/activate',
path: 'wp-scheduled-posts/v1/activate_license',
method: 'POST',
data: body,
} ).then( ( res ) => {
return res;
} );
};

export const sendOpt = async (body) => {
return apiFetch( {
path: 'wp-scheduled-posts/v1/license/submit-otp',
method: 'POST',
data: body,
} ).then( ( res ) => {
return res;
} );
}

export const getLicense = async (body) => {
return apiFetch( {
path: 'wp-scheduled-posts/v1/license/get-license',
path: 'wp-scheduled-posts/v1/get_license',
method: 'POST',
data: body,
} ).then( ( res ) => {
Expand All @@ -64,22 +55,13 @@ export const getLicense = async (body) => {

export const deActivateLicense = async () => {
return apiFetch( {
path: 'wp-scheduled-posts/v1/license/deactivate',
path: 'wp-scheduled-posts/v1/deactivate_license',
method: 'POST',
} ).then( ( res ) => {
return res;
} );
};

export const resendOtp = async (body) => {
return apiFetch( {
path: 'wp-scheduled-posts/v1/license/resend-otp',
method: 'POST',
data : body,
} ).then( ( res ) => {
return res;
} );
};

// Active social profile tab
export const generateTabURL = () => {
Expand Down

0 comments on commit 375100e

Please sign in to comment.