initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# Settings Save/Load Bug
|
||||
|
||||
The `settings` PocketBase collection has schema: `id`, `userId`, `name`, `data` (JSON). All business settings go inside the `data` JSON field.
|
||||
|
||||
## The Bug
|
||||
|
||||
Settings were saved as direct fields (`businessName`, `businessAddress`, etc.) which PocketBase silently drops because they don't match the collection schema. On reload, settings were read from those same direct fields, which were always empty.
|
||||
|
||||
## Fix in Settings.tsx
|
||||
|
||||
**Save** — wrap in `{ data: {...} }`:
|
||||
```typescript
|
||||
// ❌ Before — fields silently dropped:
|
||||
await pb.collection('settings').create({ userId, ...DEFAULT_SETTINGS });
|
||||
await pb.collection('settings').update(record.id, s);
|
||||
|
||||
// ✅ After — stored in data JSON field:
|
||||
await pb.collection('settings').create({ userId, name: 'businessSettings', data: DEFAULT_SETTINGS });
|
||||
await pb.collection('settings').update(record.id, { data: s });
|
||||
```
|
||||
|
||||
**Load** — read from `r.data` with fallback to direct fields:
|
||||
```typescript
|
||||
const d = (r.data as Record<string, unknown>) || {};
|
||||
businessName: (d.businessName as string) || (r.businessName as string) || '',
|
||||
```
|
||||
|
||||
The fallback preserves backward compatibility with any records that may have been saved at the top level.
|
||||
Reference in New Issue
Block a user