PluginProbe
Extendify / 0.10.0
Extendify v0.10.0
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 / Onboarding / pages / SiteInformation.js

SiteInformation.js in Extendify 0.10.0, at src/Onboarding/pages/SiteInformation.js

88 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useRef } from '@wordpress/element'
2 import { __ } from '@wordpress/i18n'
3 import { getOption } from '@onboarding/api/WPApi'
4 import { useFetch } from '@onboarding/hooks/useFetch'
5 import { PageLayout } from '@onboarding/layouts/PageLayout'
6 import { usePagesStore } from '@onboarding/state/Pages'
7 import { useUserSelectionStore } from '@onboarding/state/UserSelections'
8 import { pageState } from '@onboarding/state/factory'
9
10 export const fetcher = async () => ({
11 data: { title: await getOption('blogname') },
12 })
13 export const fetchData = () => ({ key: 'site-info' })
14 export const state = pageState('Site Title', (set, get) => ({
15 title: __('Site Title', 'extendify'),
16 default: undefined,
17 showInSidebar: true,
18 ready: false,
19 isDefault: () =>
20 get().default ===
21 useUserSelectionStore.getState()?.siteInformation?.title,
22 }))
23 export const SiteInformation = () => {
24 const { siteInformation, setSiteInformation } = useUserSelectionStore()
25 const initialFocus = useRef(null)
26 const nextPage = usePagesStore((state) => state.nextPage)
27 const { data: existingSiteInfo } = useFetch(fetchData, fetcher)
28
29 useEffect(() => {
30 const raf = requestAnimationFrame(() => initialFocus.current.focus())
31 return () => cancelAnimationFrame(raf)
32 }, [initialFocus])
33
34 useEffect(() => {
35 if (existingSiteInfo?.title && siteInformation?.title === undefined) {
36 setSiteInformation('title', existingSiteInfo.title)
37 state.setState({ default: existingSiteInfo.title })
38 }
39 if (existingSiteInfo?.title || siteInformation?.title) {
40 state.setState({ ready: true })
41 }
42 }, [existingSiteInfo, setSiteInformation, siteInformation])
43
44 return (
45 <PageLayout>
46 <div>
47 <h1 className="text-3xl text-partner-primary-text mb-4 mt-0">
48 {__("What's the name of your new site?", 'extendify')}
49 </h1>
50 <p className="text-base opacity-70 mb-0">
51 {__('You can change this later.', 'extendify')}
52 </p>
53 </div>
54 <div className="w-full max-w-onboarding-sm mx-auto">
55 <form
56 onSubmit={(e) => {
57 e.preventDefault()
58 nextPage()
59 }}>
60 <label
61 htmlFor="extendify-site-title-input"
62 className="block text-lg m-0 mb-4 font-semibold text-gray-900">
63 {__("What's the name of your site?", 'extendify')}
64 </label>
65 <div className="mb-8">
66 <input
67 autoComplete="off"
68 ref={initialFocus}
69 type="text"
70 name="site-title-input"
71 id="extendify-site-title-input"
72 className="w-96 max-w-full border h-12 input-focus"
73 value={siteInformation?.title ?? ''}
74 onChange={(e) => {
75 setSiteInformation('title', e.target.value)
76 }}
77 placeholder={__(
78 'Enter your preferred site title...',
79 'extendify',
80 )}
81 />
82 </div>
83 </form>
84 </div>
85 </PageLayout>
86 )
87 }
88