mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added in some error handling and a few other tiny tweaks to Add Name dialog
- Added in some error handling to catch empty names - Basic checks for trimmed strings - Subtle transition effects refs https://github.com/TryGhost/Team/issues/1682
This commit is contained in:
parent
47a8386da2
commit
ea643a4847
2 changed files with 32 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
||||||
import React, {useContext, useState} from 'react';
|
import React, {useContext, useState, useRef} from 'react';
|
||||||
|
import {Transition} from '@headlessui/react';
|
||||||
import AppContext from '../../AppContext';
|
import AppContext from '../../AppContext';
|
||||||
|
|
||||||
const AddNameDialog = (props) => {
|
const AddNameDialog = (props) => {
|
||||||
|
const inputRef = useRef(null);
|
||||||
const {dispatchAction} = useContext(AppContext);
|
const {dispatchAction} = useContext(AppContext);
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
|
@ -9,33 +11,52 @@ const AddNameDialog = (props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
await dispatchAction('updateMemberName', {
|
if (name.trim() !== '') {
|
||||||
name
|
await dispatchAction('updateMemberName', {
|
||||||
});
|
name
|
||||||
props.callback();
|
});
|
||||||
close();
|
props.callback();
|
||||||
|
close();
|
||||||
|
} else {
|
||||||
|
setError('Enter your name');
|
||||||
|
setName('');
|
||||||
|
inputRef.current.focus();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-sans font-bold tracking-tight text-[24px] mb-3 text-black">Add context to your comment</h1>
|
<h1 className="font-sans font-bold tracking-tight text-[24px] mb-3 text-black">Add context to your comment</h1>
|
||||||
<p className="font-sans text-[1.45rem] text-neutral-500 px-8 leading-9">For a healthy discussion, let other members know who you are when commenting.</p>
|
<p className="font-sans text-[1.45rem] text-neutral-500 px-8 leading-9">For a healthy discussion, let other members know who you are when commenting.</p>
|
||||||
<section className="mt-8 text-left">
|
<section className="mt-8 text-left">
|
||||||
<label htmlFor="comments-name" className="block font-sans font-medium text-sm mb-2">Name</label>
|
<div className="flex flex-row mb-2 justify-between">
|
||||||
|
<label htmlFor="comments-name" className="font-sans font-medium text-sm">Name</label>
|
||||||
|
<Transition
|
||||||
|
show={!!error}
|
||||||
|
enter="transition duration-300 ease-out"
|
||||||
|
enterFrom="opacity-0"
|
||||||
|
enterTo="opacity-100"
|
||||||
|
leave="transition duration-100 ease-out"
|
||||||
|
leaveFrom="opacity-100"
|
||||||
|
leaveTo="opacity-0"
|
||||||
|
>
|
||||||
|
<div className="font-sans text-sm text-red-500">{error}</div>
|
||||||
|
</Transition>
|
||||||
|
</div>
|
||||||
<input
|
<input
|
||||||
id="comments-name"
|
id="comments-name"
|
||||||
className="font-sans px-3 rounded border border-neutral-200 focus:border-neutral-300 w-full outline-0 h-[42px] flex items-center"
|
className={`transition-[border-color] duration-200 font-sans px-3 rounded border border-neutral-200 focus:border-neutral-300 w-full outline-0 h-[42px] flex items-center ${error && 'border-red-500 focus:border-red-500'}`}
|
||||||
type="text"
|
type="text"
|
||||||
name="name"
|
name="name"
|
||||||
|
ref={inputRef}
|
||||||
value={name}
|
value={name}
|
||||||
placeholder="Jamie Larson"
|
placeholder="Jamie Larson"
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setName(e.target.value);
|
setName(e.target.value);
|
||||||
}}
|
}}
|
||||||
// onKeyDown={e => onKeyDown(e, name)}
|
|
||||||
// onBlur={e => onBlur(e, name)}
|
|
||||||
maxLength="64"
|
maxLength="64"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -16,7 +16,7 @@ const GenericDialog = (props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Transition show={props.show} appear={true}>
|
<Transition show={props.show}>
|
||||||
<Frame type="fixed">
|
<Frame type="fixed">
|
||||||
<div>
|
<div>
|
||||||
<Transition.Child
|
<Transition.Child
|
||||||
|
|
Loading…
Add table
Reference in a new issue