Skip to content

Commit

Permalink
fix: don't use RHF to disable submit btn (#1043)
Browse files Browse the repository at this point in the history
Co-authored-by: viet nguyen <vietnguyen@noreply>
  • Loading branch information
vnugent and viet nguyen authored Dec 26, 2023
1 parent d683a30 commit f1b32c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/app/area/[[...slug]]/sections/ClimbListSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Plus } from '@phosphor-icons/react/dist/ssr'
import { ClimbList } from '@/app/editArea/[slug]/general/components/climb/ClimbListForm'
import { AreaType } from '@/js/types'
/**
Expand All @@ -17,7 +16,7 @@ export const ClimbListSection: React.FC<{ area: AreaType, editMode?: boolean }>
{!editMode &&
<div className='flex items-center gap-2'>
<a href={`/editArea/${uuid}/manageClimbs`} className='btn btn-sm btn-accent btn-outline'>
<Plus size={18} weight='bold' /> New Climbs
Add Climbs
</a>
</div>}
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/app/editArea/[slug]/general/components/AddAreaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const AddAreaForm: React.FC<{ area: AreaType }> = ({ area }) => {
<SingleEntryForm<{ areaName: string, areaType: AreaTypeFormProp }>
initialValues={{ areaName: '' }}
keepValuesAfterReset={false}
validationMode='onSubmit'
ignoreIsValid
title='Add new area'
helperText='TIP: Pick &ldquo;AREA&rdquo; if not sure. You can still change it later.'
helperText='TIP: Pick &ldquo;AREA&rdquo; type if not sure. You can change it later.'
submitHandler={async ({ areaName, areaType }) => {
const { isBoulder, isLeaf } = areaDesignationToDb(areaType)
await addOneAreaCmd({ name: areaName, parentUuid: uuid, isBoulder, isLeaf })
Expand All @@ -39,7 +41,7 @@ export const AddAreaForm: React.FC<{ area: AreaType }> = ({ area }) => {
{notEditable &&
<div role='alert' className='alert alert-info'>
<WarningOctagon size={24} />
<span>This area is either a crag or a boulder. Adding a new child area is not allowed.</span>
<span>This area is either a crag or a boulder. Adding new child areas is not allowed.</span>
</div>}
<DashboardInput
name='areaName'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export const ClimbList: React.FC<{ gradeContext: GradeContexts, climbs: ClimbTyp
const sortedClimbs = climbs.sort(leftRightIndexComparator)
return (
<div>
{climbs.length === 0 && <div className='alert alert-info text-sm'>No climbs found. Use the form below to add new climbs.</div>}
{climbs.length === 0
? (
editMode
? <NoClimbsEditModeCTA />
: <NoClimbsCTA areaId={areaMetadata.areaId} />
)
: null}
<ol className={clx(climbs.length < 5 ? 'block max-w-sm' : 'three-column-table', 'divide-y divide-base-200')}>
{sortedClimbs.map((climb, index) => {
return (
Expand Down Expand Up @@ -90,3 +96,16 @@ const DisciplinesInfo: React.FC<{ disciplines: Partial<ClimbDisciplineRecord> }>
</div>
)
}

const NoClimbsEditModeCTA: React.FC = () => (
<div className='alert alert-info text-sm'>No climbs found. Use the form below to add new climbs.</div>
)

const NoClimbsCTA: React.FC<{ areaId: string }> = ({ areaId }) => (
<div className='alert alert-info text-sm'>
No climbs found.&nbsp;
<a href={`/editArea/${areaId}/manageClimbs`} className='btn btn-sm btn-solid btn-accent'>
Add Climbs
</a>
</div>
)

1 comment on commit f1b32c7

@vercel
Copy link

@vercel vercel bot commented on f1b32c7 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.