mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-29 18:28:28 -04:00
* Add authentication dialogs for sign in and sign up - Implemented AuthDialog component to manage sign in and sign up modals. - Created SignInModal and SignUpModal components for handling respective authentication processes. - Added AuthFields component for reusable form fields and error handling. - Updated various views to utilize the new authentication dialogs instead of traditional links. - Enhanced user experience by allowing sign in and sign up actions to occur without full page reloads. - Added feature specs for testing the functionality of the new dialogs. * Refactor modals and input fields for improved accessibility and styling; adjust button sizes and text formatting * Refactor authentication forms and modals for improved usability and accessibility; integrate reCAPTCHA handling and enhance error messaging * Refactor SignUpModal layout for improved responsiveness and accessibility; organize fields into rows and enhance styling * Refactor session view spec to streamline field checks; remove redundant test and retain essential content expectations
40 lines
1.6 KiB
React
40 lines
1.6 KiB
React
import React, {useEffect, useRef, useState} from 'react';
|
|
|
|
import SignInModal from './SignInModal';
|
|
import SignUpModal from './SignUpModal';
|
|
|
|
// The sign in and sign up dialogs for every server-rendered link to either.
|
|
// Nothing of its own is drawn: it listens for clicks on any
|
|
// [data-auth-dialog="sign_in"] or [data-auth-dialog="sign_up"] link (the menu,
|
|
// the home page's buttons) and opens that dialog over the page. The layout
|
|
// mounts it once, for visitors who aren't signed in.
|
|
//
|
|
// The link's own href is the page for the same thing, so it stays the
|
|
// fallback without JavaScript.
|
|
export default function AuthDialog({urls, recaptcha_site_key: recaptchaSiteKey, site_name: siteName}) {
|
|
const [opened, setOpened] = useState(null); // 'sign_in', 'sign_up' or null
|
|
const open = useRef(null);
|
|
open.current = setOpened;
|
|
|
|
useEffect(() => {
|
|
function onClick(event) {
|
|
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey) return;
|
|
const trigger = event.target.closest('[data-auth-dialog]');
|
|
if (!trigger) return;
|
|
event.preventDefault();
|
|
open.current(trigger.dataset.authDialog);
|
|
}
|
|
|
|
document.addEventListener('click', onClick);
|
|
return () => document.removeEventListener('click', onClick);
|
|
}, []);
|
|
|
|
if (opened === 'sign_in') {
|
|
return <SignInModal urls={urls} onClose={() => setOpened(null)} onSwitch={() => setOpened('sign_up')} />;
|
|
}
|
|
if (opened === 'sign_up') {
|
|
return <SignUpModal urls={urls} recaptchaSiteKey={recaptchaSiteKey} siteName={siteName} onClose={() => setOpened(null)} onSwitch={() => setOpened('sign_in')} />;
|
|
}
|
|
return null;
|
|
}
|