From 375100e95724668fa9c9f411a4f6b9bb6909fe38 Mon Sep 17 00:00:00 2001 From: Priyo Mukul <17237437+priyomukul@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:58:25 +0600 Subject: [PATCH] Fixed: OLD License Code --- .../Settings/app/Settings/fields/License.tsx | 230 ++++++------------ .../Settings/app/Settings/helper/helper.ts | 24 +- 2 files changed, 83 insertions(+), 171 deletions(-) diff --git a/includes/Admin/Settings/app/Settings/fields/License.tsx b/includes/Admin/Settings/app/Settings/fields/License.tsx index 431e9d36..3f76bc29 100644 --- a/includes/Admin/Settings/app/Settings/fields/License.tsx +++ b/includes/Admin/Settings/app/Settings/fields/License.tsx @@ -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( @@ -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 @@ -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(); } ); } @@ -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', @@ -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 ( -
-
-

{props?.label}

-
-
- {tempKey && valid == 'valid' ? ( - setTempKey(e.target.value)} - value={tempKey} - disabled={true} - /> - ) : ( - setTempKey(e.target.value)} - value={ tempKey ? tempKey : ''} - /> - )} -
-
- {valid == 'valid' ? ( - - ) : ( - - )} + return ( +
+
+

{props?.label}

+
+
+ {tempKey && valid == 'valid' ? ( + setTempKey(e.target.value)} + value={tempKey} + disabled={true} + /> + ) : ( + setTempKey(e.target.value)} + value={ tempKey ? tempKey : ''} + /> + )} +
+
+ {valid == 'valid' ? ( + + ) : ( + + )} +
- { isRequiredOtp === 'required_otp' && - - } -
- ) + ) } -export default License \ No newline at end of file +export default License diff --git a/includes/Admin/Settings/app/Settings/helper/helper.ts b/includes/Admin/Settings/app/Settings/helper/helper.ts index c3771d00..2b32687e 100644 --- a/includes/Admin/Settings/app/Settings/helper/helper.ts +++ b/includes/Admin/Settings/app/Settings/helper/helper.ts @@ -34,7 +34,7 @@ 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 ) => { @@ -42,19 +42,10 @@ export const activateLicense = async (body) => { } ); }; -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 ) => { @@ -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 = () => {