One occurrence, revision conflicts and uncertain saves
Skip or override one original occurrence using explicit instants. An authored acknowledgement-loss and concurrent-change fixture demonstrates same-ID retry, receipt reconciliation and deliberate rebase.
Keyboard
- Choose One occurrence, its original date and Skip or Override. Apply sends one explicitly scoped change.
- An uncertain response locks editing. Retry same request or Check request receipt resolves the original identity.
- A revision conflict preserves the draft. Review against the latest snapshot before applying again.
States covered
- Occurrence or series scope
- Explicit UTC overrides
- Resource override
- Lost acknowledgement
- Same-ID retry
- Receipt reconciliation
- Concurrent revision
- Stale supplied snapshot
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-recurrence-occurrence-receipts.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useMemo,useRef,useState} from 'react';
import {Button,Checkbox,RecurrenceEditor,createMemoryRecurrenceSource,type RecurrenceSeries,type RecurrenceSource,type RecurrenceSaveResult,UIProvider} from '@bld8/ui';
const initial:RecurrenceSeries={id:'weekly-review',revision:1,title:'Weekly interface review',resourceId:'room-a',rule:{frequency:'weekly',interval:1,weekdays:[1],startDate:'2026-11-02',time:'09:00',timeZone:'UTC',durationMinutes:60,count:4,disambiguation:'reject'},exceptions:[]};
export default function OccurrenceReceiptExample(){const store=useMemo(()=>createMemoryRecurrenceSource(initial),[]),receipts=useRef(new Map<string,RecurrenceSaveResult>()),[series,setSeries]=useState(initial),[lose,setLose]=useState(false),[invalid,setInvalid]=useState(false),[staleLoad,setStaleLoad]=useState(false),[requests,setRequests]=useState<string[]>([]),[remoteRevision,setRemoteRevision]=useState(1);const flags=useRef({lose,invalid,staleLoad});flags.current={lose,invalid,staleLoad};const source=useMemo<RecurrenceSource>(()=>({load:()=>flags.current.staleLoad?initial:store.load(),receipt:async(id,{signal})=>signal.aborted?null:receipts.current.get(id)??null,save:async(request,context)=>{setRequests(values=>[...values,request.requestId]);const result=await store.save(request,context);if(result.ok){receipts.current.set(request.requestId,structuredClone(result));setRemoteRevision(store.load().revision);if(flags.current.lose){flags.current.lose=false;setLose(false);throw Error('The local acknowledgement was lost.');}if(flags.current.invalid){flags.current.invalid=false;setInvalid(false);return {...result,requestId:'mismatched-receipt'};}}return result;}}),[store]);
async function advance(){const current=store.load(),result=await store.save({requestId:'external-'+crypto.randomUUID(),change:{scope:'series',seriesId:current.id,expectedRevision:current.revision,rule:{...current.rule,durationMinutes:current.rule.durationMinutes+5}}},{signal:new AbortController().signal});if(result.ok)setRemoteRevision(result.series.revision);}
return <UIProvider><div style={{display:'grid',gap:24,maxWidth:900}}><div style={{display:'grid',gap:12}}><Checkbox label="Lose next recurrence acknowledgement" checked={lose} onCheckedChange={setLose}/><Checkbox label="Return a mismatched next receipt" checked={invalid} onCheckedChange={setInvalid}/><Checkbox label="Return stale source snapshot on load" checked={staleLoad} onCheckedChange={setStaleLoad}/><div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button variant="secondary" onClick={()=>void advance()}>Advance source revision</Button><Button variant="ghost" onClick={()=>setSeries(store.load())}>Supply current source snapshot</Button></div></div>
<RecurrenceEditor label="Occurrence editor" series={series} source={source} onSeriesChange={setSeries} resources={[{id:'room-a',label:'Review room'},{id:'room-b',label:'Quiet room'}]}/>
<p className="bui-hint" data-recurrence-revisions>{'Host revision: '+series.revision+' | Source revision: '+remoteRevision}</p><p className="bui-hint" data-recurrence-attempts>{'Attempts: '+requests.length}</p><output data-recurrence-request-ids style={{overflowWrap:'anywhere'}}>{requests.join(' | ')}</output>
<p className="bui-hint">Local reference data only. A production service owns authorization, atomic revisions and durable receipts.</p>
</div></UIProvider>;}