PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Assist / components / tasks / UpdateSiteDescription.jsx

UpdateSiteDescription.jsx in Extendify 3.2.1, at src/Assist/components/tasks/UpdateSiteDescription.jsx

93 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useTasksStore } from '@assist/state/tasks';
2 import apiFetch from '@wordpress/api-fetch';
3 import { useEffect, useRef, useState } from '@wordpress/element';
4 import { __ } from '@wordpress/i18n';
5 import classNames from 'classnames';
6
7 export const UpdateSiteDescription = ({ popModal, setModalTitle }) => {
8 const [siteDescription, setSiteDescription] = useState(undefined);
9 const [initialValue, setInitialValue] = useState(undefined);
10 const inputRef = useRef();
11 const { completeTask } = useTasksStore();
12
13 const submitChange = async () => {
14 await apiFetch({
15 path: '/wp/v2/settings',
16 method: 'POST',
17 data: {
18 description: siteDescription,
19 },
20 });
21 completeTask('site-description');
22 popModal();
23 };
24
25 useEffect(() => {
26 setModalTitle(__('Add site description', 'extendify-local'));
27 }, [setModalTitle]);
28
29 useEffect(() => {
30 const controller = new AbortController();
31
32 apiFetch({
33 path: '/wp/v2/settings',
34 signal: controller.signal,
35 }).then((settings) => {
36 setSiteDescription(settings.description);
37 setInitialValue(settings.description);
38 });
39
40 return () => controller.abort();
41 }, [setSiteDescription]);
42
43 useEffect(() => {
44 inputRef?.current?.focus();
45 }, [initialValue]);
46
47 if (typeof siteDescription === 'undefined') {
48 return <div className="h-32">{__('Loading...', 'extendify-local')}</div>;
49 }
50
51 return (
52 <form className="flex flex-col gap-6" onSubmit={(e) => e.preventDefault()}>
53 <div>
54 <label
55 className="mb-1 block text-sm text-gray-900"
56 htmlFor="extendify-site-description-input"
57 >
58 {__('Site description', 'extendify-local')}
59 </label>
60 <input
61 ref={inputRef}
62 type="text"
63 name="extendify-site-description-input"
64 id="extendify-site-description-input"
65 className="input-focus h-12 w-96 max-w-full border border-gray-900 px-2"
66 autoComplete="off"
67 data-1p-ignore
68 onChange={(e) => {
69 setSiteDescription(e.target.value);
70 }}
71 value={siteDescription}
72 placeholder={__('Enter a site description...', 'extendify-local')}
73 />
74 </div>
75 <div>
76 <button
77 type="button"
78 disabled={siteDescription === initialValue}
79 className={classNames(
80 'button-focus relative w-1/5 rounded-sm border-0 bg-design-main px-4 py-3 text-white',
81 {
82 'cursor-default opacity-50': siteDescription === initialValue,
83 },
84 )}
85 onClick={submitChange}
86 >
87 {__('Save', 'extendify-local')}
88 </button>
89 </div>
90 </form>
91 );
92 };
93