mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added frontend validation to the offers add/edit modals in AdminX
This commit is contained in:
parent
b111b7c719
commit
c2ee21a345
2 changed files with 22 additions and 3 deletions
|
@ -131,15 +131,21 @@ const Sidebar: React.FC<SidebarProps> = ({tierOptions,
|
|||
return durationOptions;
|
||||
};
|
||||
const filteredDurationOptions = getFilteredDurationOptions();
|
||||
|
||||
const [nameLength, setNameLength] = useState(0);
|
||||
const nameLengthColor = nameLength > 40 ? 'text-red' : 'text-green';
|
||||
|
||||
return (
|
||||
<div className='pt-7'>
|
||||
<Form>
|
||||
<TextField
|
||||
hint='Visible to members on Stripe Checkout page.'
|
||||
hint={<div className='flex justify-between'><span>Visible to members on Stripe Checkout page</span><strong><span className={`${nameLengthColor}`}>{nameLength}</span> / 40</strong></div>}
|
||||
maxLength={40}
|
||||
placeholder='Black Friday'
|
||||
title='Name'
|
||||
onChange={(e) => {
|
||||
handleNameInput(e);
|
||||
setNameLength(e.target.value.length);
|
||||
}}
|
||||
/>
|
||||
<section className='mt-4'>
|
||||
|
|
|
@ -31,6 +31,15 @@ const Sidebar: React.FC<{
|
|||
const handleError = useHandleError();
|
||||
const {mutateAsync: editOffer} = useEditOffer();
|
||||
|
||||
const [nameLength, setNameLength] = useState(offer?.name.length || 0);
|
||||
const nameLengthColor = nameLength > 40 ? 'text-red' : 'text-green';
|
||||
|
||||
useEffect(() => {
|
||||
if (offer?.name) {
|
||||
setNameLength(offer?.name.length);
|
||||
}
|
||||
}, [offer?.name]);
|
||||
|
||||
const offerUrl = `${getHomepageUrl(siteData!)}${offer?.code}`;
|
||||
const handleCopyClick = async () => {
|
||||
try {
|
||||
|
@ -122,12 +131,16 @@ const Sidebar: React.FC<{
|
|||
<div className='flex flex-col gap-6'>
|
||||
<TextField
|
||||
error={Boolean(errors.name)}
|
||||
hint={errors.name || 'Visible to members on Stripe Checkout page'}
|
||||
hint={errors.name || <div className='flex justify-between'><span>Visible to members on Stripe Checkout page</span><strong><span className={`${nameLengthColor}`}>{nameLength}</span> / 40</strong></div>}
|
||||
maxLength={40}
|
||||
placeholder='Black Friday'
|
||||
title='Name'
|
||||
value={offer?.name}
|
||||
onBlur={validate}
|
||||
onChange={e => updateOffer({name: e.target.value})}
|
||||
onChange={(e) => {
|
||||
setNameLength(e.target.value.length);
|
||||
updateOffer({name: e.target.value});
|
||||
}}
|
||||
onKeyDown={() => clearError('name')}
|
||||
/>
|
||||
<div className='flex flex-col gap-1.5'>
|
||||
|
|
Loading…
Add table
Reference in a new issue