mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(journey): set a journey's status by hand (#762)
This commit is contained in:
@@ -199,6 +199,22 @@ describe('JourneySettingsDialog', () => {
|
||||
expect(onSaved).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-JRN-SETTINGS-762: sets the status by hand on the spot and back to automatic', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { onRefresh } = mountDialog()
|
||||
expect(screen.getByText('Follows the dates of the linked trips. Without a trip the journey stays a draft.')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Live' }))
|
||||
await waitFor(() => expect(updateJourney).toHaveBeenCalledWith(3, { status_override: 'live' }))
|
||||
expect(onRefresh).toHaveBeenCalled()
|
||||
|
||||
updateJourney.mockClear()
|
||||
mountDialog(buildJourney({ status_override: 'completed' }))
|
||||
expect(screen.getAllByRole('button', { name: 'Completed' }).some(b => b.getAttribute('aria-pressed') === 'true')).toBe(true)
|
||||
await user.click(screen.getAllByRole('button', { name: 'Automatic' })[1])
|
||||
await waitFor(() => expect(updateJourney).toHaveBeenCalledWith(3, { status_override: null }))
|
||||
})
|
||||
|
||||
it('FE-JRN-SETTINGS-011: restores an archived journey', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDialog(buildJourney({ status: 'archived' }))
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useToast } from '../shared/Toast'
|
||||
import ConfirmDialog from '../shared/ConfirmDialog'
|
||||
import { Tooltip } from '../shared/Tooltip'
|
||||
import { DeleteButton, DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell'
|
||||
import { AddRowButton, EditorField, INPUT } from '../shared/dialogParts'
|
||||
import { AddRowButton, EditorField, INPUT, Segmented } from '../shared/dialogParts'
|
||||
import JourneyShareSection from './JourneyShareSection'
|
||||
import type { JourneyContributor, JourneyDetail } from '../../store/journeyStore'
|
||||
import { pickGradient } from '../../pages/journeyDetail/JourneyDetailPage.helpers'
|
||||
@@ -145,6 +145,23 @@ export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite,
|
||||
}
|
||||
}
|
||||
|
||||
// The state shown for the journey, set by hand (#762). Saved on the spot like
|
||||
// the switches; 'auto' stores null and hands it back to the trip dates.
|
||||
const [savingStatus, setSavingStatus] = useState(false)
|
||||
const statusChoice = journey.status_override ?? 'auto'
|
||||
const handleStatusChange = async (next: 'auto' | 'draft' | 'live' | 'completed') => {
|
||||
if (next === statusChoice || savingStatus) return
|
||||
setSavingStatus(true)
|
||||
try {
|
||||
await updateJourney(journey.id, { status_override: next === 'auto' ? null : next })
|
||||
onRefresh()
|
||||
} catch {
|
||||
toast.error(t('journey.settings.saveFailed'))
|
||||
} finally {
|
||||
setSavingStatus(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
await deleteJourney(journey.id)
|
||||
@@ -246,6 +263,27 @@ export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite,
|
||||
/>
|
||||
</EditorField>
|
||||
|
||||
{/* The journey's state, by hand or from the trips (#762) */}
|
||||
<DialogSection label={t('journey.settings.status')}>
|
||||
<div className={savingStatus ? 'opacity-60' : undefined}>
|
||||
<Segmented<'auto' | 'draft' | 'live' | 'completed'>
|
||||
label={t('journey.settings.status')}
|
||||
value={statusChoice}
|
||||
onChange={next => { void handleStatusChange(next) }}
|
||||
fill
|
||||
options={[
|
||||
{ value: 'auto', label: t('journey.settings.statusAuto') },
|
||||
{ value: 'draft', label: t('journey.status.draft') },
|
||||
{ value: 'live', label: t('journey.frontpage.live') },
|
||||
{ value: 'completed', label: t('journey.status.completed') },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<p className="m-0 mt-2 leading-normal text-content-faint" style={fs(11.5)}>
|
||||
{t(statusChoice === 'auto' ? 'journey.settings.statusAutoHint' : 'journey.settings.statusManualHint')}
|
||||
</p>
|
||||
</DialogSection>
|
||||
|
||||
{/* Trip GPX tracks on the journey map (#2194) */}
|
||||
<DialogSection label={t('journey.settings.tracks')}>
|
||||
<div className={ROWS}>
|
||||
|
||||
Reference in New Issue
Block a user