mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
feat: quality of life sweep from the feature discussions
Small requests from the discussions, each built end to end: planner and map (cycling mode, date first headings, clear a day, stay times per day, off-route stops, map lock, compact unplanned markers, pending stays, cable car, transit quick picks), places (location filter, category from OSM, open in maps, geo: link, image from an attachment, enrichment on file import, places near a pin, place name language, Amap first in China), lists and costs (packed counter, inherited sharing, Markdown to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned places, travel only, without photos), journey (photo zoom, drafts, photo order, trip suggestion, day jump), atlas (region counter, region bucket list, places per country), vacay half company holidays, studio copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for a first start restore.
This commit is contained in:
@@ -602,6 +602,23 @@ describe('TripMembersModal', () => {
|
||||
}));
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-033b: the two narrowing options post with the link (#1712)', async () => {
|
||||
const user = userEvent.setup();
|
||||
asShareOwner();
|
||||
let postedPerms: Record<string, unknown> | null = null;
|
||||
server.use(
|
||||
http.get('/api/trips/1/share-link', () => HttpResponse.json({ token: 'tok77', share_hide_images: true })),
|
||||
http.post('/api/trips/1/share-link', async ({ request }) => {
|
||||
postedPerms = (await request.json()) as Record<string, unknown>;
|
||||
return HttpResponse.json({ token: 'tok77' });
|
||||
}),
|
||||
);
|
||||
render(<TripMembersModal {...defaultProps} />);
|
||||
|
||||
await user.click(await screen.findByText('Travel & stays only'));
|
||||
await waitFor(() => expect(postedPerms).toMatchObject({ share_travel_only: true, share_hide_images: true }));
|
||||
});
|
||||
|
||||
it('FE-COMP-MEMBERS-034: a failing permission update is reported', async () => {
|
||||
const user = userEvent.setup();
|
||||
asShareOwner();
|
||||
|
||||
@@ -5,7 +5,7 @@ import CustomSelect from '../shared/CustomSelect'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
import { TripMemberAvatar as Avatar } from './TripMemberAvatar'
|
||||
import TripShareDialog from './TripShareDialog'
|
||||
import { useShareLink, useTripInviteLink, useTripMembers } from './useTripShare'
|
||||
import { SHARE_OPTIONS, SHARE_SECTIONS, useShareLink, useTripInviteLink, useTripMembers } from './useTripShare'
|
||||
|
||||
function ShareLinkSection({ tripId, t }: { tripId: number; t: (key: string, params?: Record<string, string | number>) => string }) {
|
||||
const { loading, url: shareUrl, perms, copied, create: handleCreate, setPerm, remove: handleDelete, copy: handleCopy } = useShareLink(tripId)
|
||||
@@ -23,13 +23,7 @@ function ShareLinkSection({ tripId, t }: { tripId: number; t: (key: string, para
|
||||
|
||||
{/* Permission checkboxes */}
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 12 }}>
|
||||
{[
|
||||
{ key: 'share_map', label: t('share.permMap'), always: true },
|
||||
{ key: 'share_bookings', label: t('share.permBookings') },
|
||||
{ key: 'share_packing', label: t('share.permPacking') },
|
||||
{ key: 'share_budget', label: t('share.permBudget') },
|
||||
{ key: 'share_collab', label: t('share.permCollab') },
|
||||
].map(opt => (
|
||||
{[...SHARE_SECTIONS, ...SHARE_OPTIONS].map(opt => ({ ...opt, label: t(opt.label), always: 'always' in opt && !!opt.always })).map(opt => (
|
||||
<button type="button" key={opt.key} onClick={() => !opt.always && handleUpdatePerms(opt.key, !perms[opt.key])}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 5, padding: '4px 10px', borderRadius: 20,
|
||||
|
||||
@@ -5,9 +5,9 @@ import CustomSelect from '../shared/CustomSelect'
|
||||
import ConfirmDialog from '../shared/ConfirmDialog'
|
||||
import { Tooltip } from '../shared/Tooltip'
|
||||
import { DialogButton, DialogHeader, DialogSection, DialogShell, DialogTile, NEUTRAL_TINT, PILL, fs } from '../shared/DialogShell'
|
||||
import { AddRowButton, INPUT, PANEL } from '../shared/dialogParts'
|
||||
import { AddRowButton, INPUT, LABEL, PANEL } from '../shared/dialogParts'
|
||||
import { TripMemberAvatar } from './TripMemberAvatar'
|
||||
import { useShareLink, useTripInviteLink, useTripMembers, type SharePerm, type TripMembersState } from './useTripShare'
|
||||
import { SHARE_OPTIONS, SHARE_SECTIONS, useShareLink, useTripInviteLink, useTripMembers, type TripMembersState } from './useTripShare'
|
||||
|
||||
interface TripShareDialogProps {
|
||||
isOpen: boolean
|
||||
@@ -306,13 +306,17 @@ function LinkCard({ icon, title, hint, children }: { icon: ReactNode; title: str
|
||||
)
|
||||
}
|
||||
|
||||
const SHARE_PERMS: { key: SharePerm; label: string; always?: boolean }[] = [
|
||||
{ key: 'share_map', label: 'share.permMap', always: true },
|
||||
{ key: 'share_bookings', label: 'share.permBookings' },
|
||||
{ key: 'share_packing', label: 'share.permPacking' },
|
||||
{ key: 'share_budget', label: 'share.permBudget' },
|
||||
{ key: 'share_collab', label: 'share.permCollab' },
|
||||
]
|
||||
/** One toggle of the link, a filled pill with a tick while it is on. */
|
||||
function PermChip({ on, disabled, label, hint, onToggle }: { on: boolean; disabled?: boolean; label: string; hint?: string; onToggle: () => void }) {
|
||||
const chip = (
|
||||
<button type="button" aria-pressed={on} disabled={disabled} onClick={onToggle}
|
||||
className={`inline-flex items-center gap-1 rounded-full px-2.5 py-1 font-semibold disabled:cursor-default ${on ? 'bg-accent text-accent-text disabled:opacity-70' : 'bg-surface-card text-content-muted ring-1 ring-edge-faint hover:text-content'}`}
|
||||
style={fs(11.5, 'body')}>
|
||||
{on && <Check size={11} strokeWidth={2.6} />}{label}
|
||||
</button>
|
||||
)
|
||||
return hint ? <Tooltip label={hint}>{chip}</Tooltip> : chip
|
||||
}
|
||||
|
||||
/** The read-only public link, and which parts of the trip it shows. */
|
||||
function PublicLink({ tripId }: { tripId: number }) {
|
||||
@@ -322,17 +326,19 @@ function PublicLink({ tripId }: { tripId: number }) {
|
||||
return (
|
||||
<LinkCard icon={<Link2 size={15} strokeWidth={2.2} />} title={t('share.linkTitle')} hint={t('share.linkHint')}>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{SHARE_PERMS.map(opt => {
|
||||
const on = link.perms[opt.key]
|
||||
return (
|
||||
<button key={opt.key} type="button" aria-pressed={on} disabled={opt.always}
|
||||
onClick={() => void link.setPerm(opt.key, !on)}
|
||||
className={`inline-flex items-center gap-1 rounded-full px-2.5 py-1 font-semibold disabled:cursor-default ${on ? 'bg-accent text-accent-text disabled:opacity-70' : 'bg-surface-card text-content-muted ring-1 ring-edge-faint hover:text-content'}`}
|
||||
style={fs(11.5, 'body')}>
|
||||
{on && <Check size={11} strokeWidth={2.6} />}{t(opt.label)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
{SHARE_SECTIONS.map(opt => (
|
||||
<PermChip key={opt.key} on={link.perms[opt.key]} disabled={opt.always} label={t(opt.label)}
|
||||
onToggle={() => void link.setPerm(opt.key, !link.perms[opt.key])} />
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<span className={LABEL}>{t('share.options')}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{SHARE_OPTIONS.map(opt => (
|
||||
<PermChip key={opt.key} on={link.perms[opt.key]} label={t(opt.label)} hint={t(`${opt.label}Hint`)}
|
||||
onToggle={() => void link.setPerm(opt.key, !link.perms[opt.key])} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{link.url ? (
|
||||
<>
|
||||
|
||||
@@ -13,10 +13,28 @@ import { copyText } from '../../utils/clipboard'
|
||||
// phone opens from its More sheet. The questions ("Remove this member?") are the
|
||||
// caller's: the desktop asks in a dialog of its own, the phone with the browser's.
|
||||
|
||||
export type SharePerm = 'share_map' | 'share_bookings' | 'share_packing' | 'share_budget' | 'share_collab'
|
||||
export type SharePerm = 'share_map' | 'share_bookings' | 'share_packing' | 'share_budget' | 'share_collab' | 'share_travel_only' | 'share_hide_images'
|
||||
type SharePerms = Record<SharePerm, boolean>
|
||||
|
||||
const DEFAULT_PERMS: SharePerms = { share_map: true, share_bookings: true, share_packing: false, share_budget: false, share_collab: false }
|
||||
const DEFAULT_PERMS: SharePerms = {
|
||||
share_map: true, share_bookings: true, share_packing: false, share_budget: false, share_collab: false,
|
||||
share_travel_only: false, share_hide_images: false,
|
||||
}
|
||||
|
||||
/** What the link shows, one tab each. */
|
||||
export const SHARE_SECTIONS: { key: SharePerm; label: string; always?: boolean }[] = [
|
||||
{ key: 'share_map', label: 'share.permMap', always: true },
|
||||
{ key: 'share_bookings', label: 'share.permBookings' },
|
||||
{ key: 'share_packing', label: 'share.permPacking' },
|
||||
{ key: 'share_budget', label: 'share.permBudget' },
|
||||
{ key: 'share_collab', label: 'share.permCollab' },
|
||||
]
|
||||
|
||||
/** How the plan it shows is narrowed (#1712). */
|
||||
export const SHARE_OPTIONS: { key: SharePerm; label: string }[] = [
|
||||
{ key: 'share_travel_only', label: 'share.optTravelOnly' },
|
||||
{ key: 'share_hide_images', label: 'share.optHideImages' },
|
||||
]
|
||||
|
||||
/** Copy text and show "Copied" for two seconds, the timer restarting on every copy. */
|
||||
function useCopied() {
|
||||
@@ -44,7 +62,11 @@ export function useShareLink(tripId: number) {
|
||||
useEffect(() => {
|
||||
shareApi.getLink(tripId).then(d => {
|
||||
setToken(d.token)
|
||||
if (d.token) setPerms({ share_map: d.share_map ?? true, share_bookings: d.share_bookings ?? true, share_packing: d.share_packing ?? false, share_budget: d.share_budget ?? false, share_collab: d.share_collab ?? false })
|
||||
if (d.token) setPerms({
|
||||
share_map: d.share_map ?? true, share_bookings: d.share_bookings ?? true, share_packing: d.share_packing ?? false,
|
||||
share_budget: d.share_budget ?? false, share_collab: d.share_collab ?? false,
|
||||
share_travel_only: d.share_travel_only ?? false, share_hide_images: d.share_hide_images ?? false,
|
||||
})
|
||||
setLoading(false)
|
||||
}).catch(() => setLoading(false))
|
||||
}, [tripId])
|
||||
|
||||
Reference in New Issue
Block a user