-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathAnyoneCanRegisterDisabledNotice.js
130 lines (120 loc) · 3.55 KB
/
AnyoneCanRegisterDisabledNotice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Site Kit by Google, Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { createInterpolateElement, Fragment } from '@wordpress/element';
import { __, _x, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { useSelect, useDispatch } from 'googlesitekit-data';
import {
CORE_USER,
PERMISSION_MANAGE_OPTIONS,
} from '../../../../googlesitekit/datastore/user/constants';
import { CORE_SITE } from '../../../../googlesitekit/datastore/site/constants';
import {
BREAKPOINT_DESKTOP,
BREAKPOINT_XLARGE,
useBreakpoint,
} from '../../../../hooks/useBreakpoint';
import SettingsNotice, {
TYPE_INFO,
} from '../../../../components/SettingsNotice';
import Link from '../../../../components/Link';
import InfoIcon from '../../../../../svg/icons/info-circle.svg';
const ANYONE_CAN_REGISTER_DISABLED_NOTICE =
'sign-in-with-google-anyone-can-register-notice';
export default function AnyoneCanRegisterDisabledNotice( { className } ) {
const breakpoint = useBreakpoint();
const canManageOptions = useSelect( ( select ) =>
select( CORE_USER ).hasCapability( PERMISSION_MANAGE_OPTIONS )
);
const isMultisite = useSelect( ( select ) =>
select( CORE_SITE ).isMultisite()
);
const generalSettingsURL = useSelect(
( select ) =>
new URL(
isMultisite ? 'network/settings.php' : 'options-general.php',
select( CORE_SITE ).getAdminURL()
).href
);
const anyoneCanRegister = useSelect( ( select ) =>
select( CORE_SITE ).getAnyoneCanRegister()
);
const isDismissed = useSelect( ( select ) =>
select( CORE_USER ).isItemDismissed(
ANYONE_CAN_REGISTER_DISABLED_NOTICE
)
);
const { dismissItem } = useDispatch( CORE_USER );
if ( isDismissed === true || anyoneCanRegister === true ) {
return null;
}
return (
<SettingsNotice
className={ classnames(
'googlesitekit-anyone-can-register-disabled-notice',
className
) }
type={ TYPE_INFO }
Icon={ InfoIcon }
dismiss
dismissCallback={ () =>
dismissItem( ANYONE_CAN_REGISTER_DISABLED_NOTICE )
}
dismissLabel={ __( 'Got it', 'google-site-kit' ) }
notice={ createInterpolateElement(
sprintf(
/* translators: %1$s: Setting name, %2$s: Sign in with Google service name */
__(
'Enable the %1$s setting to allow your visitors to create an account using the %2$s button. <br/>Visit <a>WordPress Settings</a> to manage this setting.',
'google-site-kit'
),
isMultisite
? __( '“Allow new registrations”', 'google-site-kit' )
: __( '“Anyone can register”', 'google-site-kit' ),
_x(
'Sign in with Google',
'Service name',
'google-site-kit'
)
),
{
a:
! canManageOptions && isMultisite ? (
<span />
) : (
<Link key="link" href={ generalSettingsURL } />
),
br:
breakpoint === BREAKPOINT_XLARGE ||
breakpoint === BREAKPOINT_DESKTOP ? (
<br />
) : (
<Fragment />
),
}
) }
/>
);
}