PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.16.6
GiveWP – Donation Plugin and Fundraising Platform v4.16.6
4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / DonorDashboards / resources / js / app / components / auth-modal / index.js
give / src / DonorDashboards / resources / js / app / components / auth-modal Last commit date
utils 2 years ago index.js 2 years ago style.scss 4 years ago
index.js
217 lines
1 import {useState, Fragment} from 'react';
2 import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
3 import {__} from '@wordpress/i18n';
4 import TextControl from '../text-control';
5 import Button from '../button';
6
7 import {loginWithAPI, verifyEmailWithAPI, resetPasswordWithAPI} from './utils';
8 import {getWindowData} from '../../utils';
9
10 import ReCAPTCHA from 'react-google-recaptcha';
11
12 import './style.scss';
13
14 const AuthModal = () => {
15 const [recaptcha, setRecaptcha] = useState('');
16 const [email, setEmail] = useState('');
17 const [login, setLogin] = useState('');
18 const [password, setPassword] = useState('');
19 const [loginError, setLoginError] = useState(null);
20 const [loggingIn, setLoggingIn] = useState(false);
21 const [verifyingEmail, setVerifyingEmail] = useState(false);
22 const [emailSent, setEmailSent] = useState(false);
23 const [emailError, setEmailError] = useState(null);
24 const [passwordResetEmail, setPasswordResetEmail] = useState('');
25 const [showPasswordReset, setShowPasswordReset] = useState(false);
26 const [passwordResetSent, setPasswordResetSent] = useState(false);
27 const emailAccessEnabled = getWindowData('emailAccessEnabled');
28 const loggedInWithoutDonor = getWindowData('loggedInWithoutDonor');
29 const recaptchaKey = getWindowData('recaptchaKey');
30 const loginEnabled = getWindowData('loginEnabled');
31
32 const handleLogin = async (e) => {
33 e.preventDefault();
34 if (login && password) {
35 setLoggingIn(true);
36 // eslint-disable-next-line camelcase
37 const {status, response, body_response} = await loginWithAPI({
38 login,
39 password,
40 });
41
42 if (status === 200) {
43 window.location.reload();
44 } else {
45 setLoggingIn(false);
46 setLoginError(body_response.message);
47 if (response === 'unidentified_login') {
48 setLogin('');
49 setPassword('');
50 } else {
51 setPassword('');
52 }
53 }
54 }
55 };
56
57 const handleVerifyEmail = async (e) => {
58 e.preventDefault();
59 if (email) {
60 setVerifyingEmail(true);
61 // eslint-disable-next-line camelcase
62 const {status, body_response} = await verifyEmailWithAPI({
63 email,
64 recaptcha,
65 });
66
67 setVerifyingEmail(false);
68
69 if (status === 200) {
70 setEmailSent(true);
71 } else {
72 setEmailError(body_response.message);
73 }
74 }
75 };
76
77 const handlePasswordReset = async (e) => {
78 e.preventDefault();
79 if (passwordResetEmail) {
80 // eslint-disable-next-line camelcase
81 const {status, body_response} = await resetPasswordWithAPI(passwordResetEmail);
82
83 if (status === 200) {
84 setPasswordResetSent(true);
85 setShowPasswordReset(false);
86 } else {
87 setEmailError(body_response.message);
88 }
89 }
90 };
91
92 return (
93 <div className="give-donor-dashboard__auth-modal">
94 <div className="give-donor-dashboard__auth-modal-frame">
95 <div className="give-donor-dashboard__auth-modal-heading">
96 {__('Log in to see your donor dashboard', 'give')}
97 </div>
98 <div className="give-donor-dashboard__auth-modal-content">
99 {loggedInWithoutDonor && (
100 <div className="give-donor-dashboard__auth-modal-notice">
101 {__(
102 'The account you are currently logged into the site with does not have any donations associated with it. Donate now or contact the site administrator to associate this WordPress user with an existing donor.',
103 'give'
104 )}
105 </div>
106 )}
107 {emailAccessEnabled && (
108 <Fragment>
109 <div className="give-donor-dashboard__auth-modal-instruction">
110 {__(
111 "For privacy, enter the email address used to make a donation below and we'll send you a link to access your donor dashboard.",
112 'give'
113 )}
114 </div>
115 <form
116 className="give-donor-dashboard__auth-modal-form"
117 onSubmit={(e) => handleVerifyEmail(e)}
118 >
119 <TextControl icon="envelope" value={email} onChange={(value) => setEmail(value)} />
120 {recaptchaKey && <ReCAPTCHA sitekey={recaptchaKey} onChange={setRecaptcha} />}
121 <div className="give-donor-dashboard__auth-modal-row">
122 <Button type="submit">
123 {emailSent === false ? __('Verify Email', 'give') : __('Email Sent', 'give')}
124 {emailSent === false && (
125 <FontAwesomeIcon
126 className={
127 verifyingEmail ? 'give-donor-dashboard__auth-modal-spinner' : ''
128 }
129 icon={verifyingEmail ? 'spinner' : 'chevron-right'}
130 fixedWidth
131 />
132 )}
133 </Button>
134 {emailError && (
135 <div className="give-donor-dashboard__auth-modal-error">{emailError}</div>
136 )}
137 </div>
138 </form>
139 </Fragment>
140 )}
141 {emailAccessEnabled && loginEnabled && (
142 <div className="give-donor-dashboard__auth-modal-seperator" />
143 )}
144 {loginEnabled && (
145 <>
146 {showPasswordReset && (
147 <>
148 <div className="give-donor-dashboard__auth-modal-instruction">
149 {__('Reset your password by entering your email address.', 'give')}
150 </div>
151 <form className="give-donor-dashboard__auth-modal-form" onSubmit={(e) => handlePasswordReset(e)}>
152 <TextControl icon="envelope" value={passwordResetEmail} onChange={(value) => setPasswordResetEmail(value)} />
153 <div className="give-donor-dashboard__auth-modal-row">
154 <Button type="submit">
155 {__('Reset Password', 'give')}
156 <FontAwesomeIcon
157 className={loggingIn ? 'give-donor-dashboard__auth-modal-spinner' : ''}
158 icon={loggingIn ? 'spinner' : 'chevron-right'}
159 fixedWidth
160 />
161 </Button>
162 </div>
163 </form>
164 </>
165 )}
166 {!showPasswordReset && (
167 <>
168 <div className="give-donor-dashboard__auth-modal-instruction">
169 {emailAccessEnabled && (
170 <Fragment>
171 {__('Already have an account?', 'give')} <br />
172 </Fragment>
173 )}
174 {__('Log in below to access your dashboard', 'give')}
175 </div>
176 <form className="give-donor-dashboard__auth-modal-form" onSubmit={(e) => handleLogin(e)}>
177 <TextControl icon="user" value={login} onChange={(value) => setLogin(value)} />
178 <TextControl
179 icon="lock"
180 type="password"
181 value={password}
182 onChange={(value) => setPassword(value)}
183 />
184 <div className="give-donor-dashboard__auth-modal-row">
185 <Button type="submit">
186 {__('Log in', 'give')}
187 <FontAwesomeIcon
188 className={loggingIn ? 'give-donor-dashboard__auth-modal-spinner' : ''}
189 icon={loggingIn ? 'spinner' : 'chevron-right'}
190 fixedWidth
191 />
192 </Button>
193 <Button type="button" onClick={() => setShowPasswordReset(true)}>{__('Forgot Password?', 'give')}</Button>
194 {loginError && (
195 <div className="give-donor-dashboard__auth-modal-error">{loginError}</div>
196 )}
197 </div>
198 </form>
199 </>
200 )}
201 {passwordResetSent && (
202 <>
203 <div className="give-donor-dashboard__auth-modal-instruction">
204 {__('Instructions for resetting your password have been sent to you email.', 'give')}
205 </div>
206 </>
207 )}
208 </>
209 )}
210 </div>
211 </div>
212 </div>
213 );
214 };
215
216 export default AuthModal;
217