mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Disable staging mode from the data types that don't need it
This commit is contained in:
@@ -35,6 +35,7 @@ export const DetailView = <T extends object>({
|
||||
validator,
|
||||
isNew = false,
|
||||
isUserPage = false,
|
||||
hasStagingMode = false,
|
||||
}: {
|
||||
tabs: TabType[]
|
||||
data: T
|
||||
@@ -42,6 +43,7 @@ export const DetailView = <T extends object>({
|
||||
validator: (editData: EditDataType<T>, field: keyof EditDataType<T>) => ValidationObject
|
||||
isNew?: boolean
|
||||
isUserPage?: boolean
|
||||
hasStagingMode?: boolean
|
||||
}) => {
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const theme = useTheme()
|
||||
@@ -144,7 +146,9 @@ export const DetailView = <T extends object>({
|
||||
<EditIcon style={{ marginRight: '0.5em' }} /> {mode.read ? 'Edit' : 'Cancel edit'}
|
||||
</Button>
|
||||
)}
|
||||
{(!mode.read || initialState.mode.new) && onWrite && <WriteButton onWrite={onWrite} />}
|
||||
{(!mode.read || initialState.mode.new) && onWrite && (
|
||||
<WriteButton onWrite={onWrite} hasStagingMode={hasStagingMode} />
|
||||
)}
|
||||
</Box>
|
||||
{!isUserPage && (
|
||||
<Box sx={{ marginRight: '3em' }}>
|
||||
|
||||
@@ -7,19 +7,25 @@ import { useDetailContext } from './Context/DetailContext'
|
||||
import { EditDataType } from '@/backendTypes'
|
||||
import { useState } from 'react'
|
||||
|
||||
export const WriteButton = <T,>({ onWrite }: { onWrite: (editData: EditDataType<T>) => Promise<void> }) => {
|
||||
export const WriteButton = <T,>({
|
||||
onWrite,
|
||||
hasStagingMode = false,
|
||||
}: {
|
||||
onWrite: (editData: EditDataType<T>) => Promise<void>
|
||||
hasStagingMode?: boolean
|
||||
}) => {
|
||||
const { editData, mode, setMode } = useDetailContext<T>()
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const getButtonText = () => {
|
||||
if (!mode.staging) return 'Finalize entry'
|
||||
if (!mode.staging) return hasStagingMode ? 'Finalize entry' : 'Save changes'
|
||||
return 'Complete and save'
|
||||
}
|
||||
return (
|
||||
<Button
|
||||
sx={{ width: '20em' }}
|
||||
onClick={() => {
|
||||
if (!mode.staging) {
|
||||
if (!mode.staging && hasStagingMode) {
|
||||
setMode(mode.new ? 'staging-new' : 'staging-edit')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ export const LocalityDetails = () => {
|
||||
isNew={isNew}
|
||||
onWrite={onWrite}
|
||||
validator={validateLocality}
|
||||
hasStagingMode
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ export const SpeciesDetails = () => {
|
||||
data={isNew ? emptySpecies : data!}
|
||||
onWrite={onWrite}
|
||||
isNew={isNew}
|
||||
hasStagingMode
|
||||
validator={() => ({
|
||||
name: 'unknown',
|
||||
error: null,
|
||||
|
||||
@@ -41,6 +41,7 @@ export const TimeBoundDetails = () => {
|
||||
<DetailView
|
||||
tabs={tabs}
|
||||
data={isNew ? emptyTimeBound : data!}
|
||||
hasStagingMode
|
||||
isNew={isNew}
|
||||
onWrite={onWrite}
|
||||
validator={() => ({
|
||||
|
||||
@@ -39,6 +39,7 @@ export const TimeUnitDetails = () => {
|
||||
<DetailView
|
||||
tabs={tabs}
|
||||
isNew={isNew}
|
||||
hasStagingMode
|
||||
data={isNew ? emptyTimeUnit : data!}
|
||||
onWrite={onWrite}
|
||||
validator={() => ({ name: '', error: null })}
|
||||
|
||||
Reference in New Issue
Block a user