| 1 |
import axios from "axios"; |
| 2 |
import { __ } from "@wordpress/i18n"; |
| 3 |
import toast from "react-hot-toast"; |
| 4 |
import { Modal, Spinner } from "@wordpress/components"; |
| 5 |
import { Arrow, InfoIcon } from "../../../icons/icons"; |
| 6 |
import { createInterpolateElement } from "@wordpress/element"; |
| 7 |
|
| 8 |
export const saveSettingOptions = async (settings, actionType = "save", setSettingsOptions, shareData) => { |
| 9 |
try { |
| 10 |
const formData = new FormData(); |
| 11 |
|
| 12 |
formData.append("nonce", sp_pcp_block_settings.nonce); |
| 13 |
formData.append("action", "sp_pcp_update_setting_options"); |
| 14 |
formData.append("optionData", JSON.stringify(settings)); |
| 15 |
if (shareData !== undefined) { |
| 16 |
formData.append("shareData", JSON.stringify(shareData)); |
| 17 |
} |
| 18 |
|
| 19 |
const response = await axios.post(ajaxurl, formData); |
| 20 |
|
| 21 |
if (response?.data?.success) { |
| 22 |
if (actionType === "save") { |
| 23 |
toastSuccessMsg(__("Saved successfully", "post-carousel")); |
| 24 |
} else { |
| 25 |
toastSuccessMsg(__("Reset successfully", "post-carousel")); |
| 26 |
} |
| 27 |
setSettingsOptions(response?.data?.data?.options); |
| 28 |
} else { |
| 29 |
toastErrorMsg(__("Something Went Wrong", "post-carousel")); |
| 30 |
return { success: false, data: response.data }; |
| 31 |
} |
| 32 |
} catch (error) { |
| 33 |
toastErrorMsg(__("Something Went Wrong", "post-carousel")); |
| 34 |
console.error(error); |
| 35 |
return { success: false, error }; |
| 36 |
} |
| 37 |
}; |
| 38 |
|
| 39 |
export const toastSuccessMsg = (message) => { |
| 40 |
return toast.success(message, { |
| 41 |
style: { |
| 42 |
marginTop: "28px", |
| 43 |
fontSize: "15px", |
| 44 |
padding: "10px 18px", |
| 45 |
}, |
| 46 |
}); |
| 47 |
}; |
| 48 |
|
| 49 |
export const toastErrorMsg = (message) => { |
| 50 |
return toast.error(message, { |
| 51 |
style: { |
| 52 |
marginTop: "28px", |
| 53 |
fontSize: "15px", |
| 54 |
padding: "10px 18px", |
| 55 |
}, |
| 56 |
}); |
| 57 |
}; |
| 58 |
|
| 59 |
export const UserDataInfoModal = ({ closeModal }) => { |
| 60 |
return ( |
| 61 |
<Modal |
| 62 |
title={__("What We Collect?", "post-carousel")} |
| 63 |
onRequestClose={closeModal} |
| 64 |
className="sp-smart-post-setup-page-modal" |
| 65 |
> |
| 66 |
<hr /> |
| 67 |
<p className="modal-description"> |
| 68 |
{__( |
| 69 |
"We collect only non-sensitive diagnostic data and basic plugin usage information. This may include:", |
| 70 |
"post-carousel" |
| 71 |
)} |
| 72 |
</p> |
| 73 |
<ul> |
| 74 |
<li className="modal-description">{__("WordPress & PHP version", "post-carousel")}</li> |
| 75 |
<li className="modal-description">{__("Active theme and plugins", "post-carousel")}</li> |
| 76 |
<li className="modal-description">{__("General system details", "post-carousel")}</li> |
| 77 |
<li className="modal-description"> |
| 78 |
{__("Email address only for sending helpful updates or optional offers.", "post-carousel")} |
| 79 |
</li> |
| 80 |
</ul> |
| 81 |
<p className="modal-description"> |
| 82 |
{__( |
| 83 |
"This information helps us improve performance, fix issues faster, and ensure Smart Post stays compatible with the popular plugins and themes.", |
| 84 |
"post-carousel" |
| 85 |
)} |
| 86 |
</p> |
| 87 |
<p className="modal-description"> |
| 88 |
<b>{__( |
| 89 |
"No personal data is collected, and we never send spam—promise.", |
| 90 |
"post-carousel" |
| 91 |
)}</b> |
| 92 |
</p> |
| 93 |
<p className="modal-description"> |
| 94 |
<b>{__("Your privacy comes first.", "post-carousel")}</b> |
| 95 |
{" "} |
| 96 |
<a href="https://wpsmartpost.com/information-we-collect/" target="_blank" className="modal-description"> |
| 97 |
{__("Learn More", "post-carousel")} |
| 98 |
<Arrow /> |
| 99 |
</a> |
| 100 |
</p> |
| 101 |
</Modal> |
| 102 |
); |
| 103 |
}; |
| 104 |
|
| 105 |
export const InfoText = ({ text }) => { |
| 106 |
return ( |
| 107 |
<span className="sp-pcp-settings-info"> |
| 108 |
<InfoIcon /> |
| 109 |
<span className="sp-pcp-settings-info-text">{text}</span> |
| 110 |
</span> |
| 111 |
); |
| 112 |
}; |
| 113 |
|
| 114 |
export const renderInfoText = (label) => { |
| 115 |
const infoTexts = { |
| 116 |
cleanOnDeletion: __( |
| 117 |
"Check this box if you would like Smart Post to completely clean-up all of its data when the plugin is deleted.", |
| 118 |
"post-carousel" |
| 119 |
), |
| 120 |
siteMode: createInterpolateElement( |
| 121 |
__( |
| 122 |
`Choose a mode based on your website's current status. |
| 123 |
<strong>Live:</strong> Select this when your website is ready for visitors and should be fully accessible. |
| 124 |
<strong>Coming Soon:</strong> Choose this if your site is still in progress and not ready to go public. |
| 125 |
<strong>Maintenance:</strong> Use this when updating your site and temporarily limiting visitor access.`, |
| 126 |
"post-carousel" |
| 127 |
), |
| 128 |
{ |
| 129 |
strong: <strong />, |
| 130 |
} |
| 131 |
), |
| 132 |
// ... other info texts will be added here if necessary. |
| 133 |
}; |
| 134 |
return infoTexts[label]; |
| 135 |
}; |
| 136 |
|
| 137 |
export const SaveAndReset = ({ onSave, onReset, isChanged, isSaving }) => { |
| 138 |
const SaveIcon = () => ( |
| 139 |
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="16" height="16" viewBox="0 0 24 24" style={{ enableBackground: 'new 0 0 24 24' }} xmlSpace="preserve"> |
| 140 |
<style type="text/css"> |
| 141 |
{`.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#FFFFFF;}.st1{fill:none;stroke:#000000;stroke-width:1.4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:187.5;}.st2{fill-rule:evenodd;clip-rule:evenodd;}.st3{fill-rule:evenodd;clip-rule:evenodd;fill:none;stroke:#000000;stroke-width:2.2;stroke-linejoin:round;stroke-miterlimit:10;}.st4{fill:#FFFFFF;}`} |
| 142 |
</style> |
| 143 |
<path className="st4" d="M23.4,6.6l-6.1-6C17,0.2,16.5,0,16,0H3.2C1.4,0,0,1.4,0,3.2v17.6C0,22.6,1.4,24,3.2,24h17.6 c1.8,0,3.2-1.4,3.2-3.2V8C24,7.4,23.8,7,23.4,6.6z M8.1,2.2h5.7v2.9H8.1V2.2z M17.1,21.8H6.9V15h10.2V21.8z M21.8,20.8 c0,0.5-0.4,1-1,1h-1.5v-7.4c0-0.9-0.7-1.6-1.6-1.6H6.3c-0.9,0-1.6,0.7-1.6,1.6v7.4H3.2c-0.5,0-1-0.4-1-1V3.2c0-0.5,0.4-1,1-1h2.7 v3.5c0,0.9,0.7,1.6,1.6,1.6h7c0.9,0,1.6-0.7,1.6-1.6V2.3l5.8,5.8V20.8z"/> |
| 144 |
</svg> |
| 145 |
); |
| 146 |
|
| 147 |
return ( |
| 148 |
<div className={`sp-pcp-settings-save-wrapper`}> |
| 149 |
<button className={`sp-pcp-settings-save-btn ${isChanged ? "active" : ""}`} onClick={onSave}> |
| 150 |
{isSaving ? ( |
| 151 |
<> |
| 152 |
<Spinner /> {__("Saving…", "post-carousel")} |
| 153 |
</> |
| 154 |
) : ( |
| 155 |
<> |
| 156 |
<SaveIcon /> {__("Save Changes", "post-carousel")} |
| 157 |
</> |
| 158 |
)} |
| 159 |
</button> |
| 160 |
{onReset && ( |
| 161 |
<button className="sp-pcp-settings-reset-btn" onClick={onReset}> |
| 162 |
{__("Reset", "post-carousel")} |
| 163 |
</button> |
| 164 |
)} |
| 165 |
</div> |
| 166 |
); |
| 167 |
}; |
| 168 |
|