fix: loyalty tier crash, chat duplicate rooms, sidebar defaults
- LoyaltyPage: levelBadge() now falls back to bronze for unknown tiers (DB had loyalty_tier='standard' from old seed data) - migration 040: deduplicate general chat rooms + add unique index, normalize loyalty_tier to bronze for non-standard values - chat.ts: ON CONFLICT clause now targets the new partial unique index - Sidebar: DEFAULT_GROUPS only opens 'basics' by default; bump localStorage key to sidebarGroups_v2 to clear stale stored state Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,16 +33,16 @@ type GroupKey = 'basics' | 'prices' | 'service' | 'management' | 'settingsGroup'
|
||||
|
||||
const DEFAULT_GROUPS: Record<GroupKey, boolean> = {
|
||||
basics: true,
|
||||
prices: true,
|
||||
service: true,
|
||||
management: true,
|
||||
settingsGroup: true,
|
||||
devGroup: true,
|
||||
prices: false,
|
||||
service: false,
|
||||
management: false,
|
||||
settingsGroup: false,
|
||||
devGroup: false,
|
||||
}
|
||||
|
||||
function loadGroups(): Record<GroupKey, boolean> {
|
||||
try {
|
||||
const stored = JSON.parse(localStorage.getItem('sidebarGroups') || '{}')
|
||||
const stored = JSON.parse(localStorage.getItem('sidebarGroups_v2') || '{}')
|
||||
return { ...DEFAULT_GROUPS, ...stored }
|
||||
} catch {
|
||||
return { ...DEFAULT_GROUPS }
|
||||
@@ -50,7 +50,7 @@ function loadGroups(): Record<GroupKey, boolean> {
|
||||
}
|
||||
|
||||
function saveGroups(groups: Record<GroupKey, boolean>) {
|
||||
localStorage.setItem('sidebarGroups', JSON.stringify(groups))
|
||||
localStorage.setItem('sidebarGroups_v2', JSON.stringify(groups))
|
||||
}
|
||||
|
||||
// ── NavItem with star ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -214,8 +214,9 @@ const MANUAL_REASONS = [
|
||||
'Другое',
|
||||
]
|
||||
|
||||
function levelBadge(levelId: LevelId) {
|
||||
const level = DEFAULT_LEVELS.find(l => l.id === levelId)!
|
||||
function levelBadge(levelId: string) {
|
||||
const level = DEFAULT_LEVELS.find(l => l.id === levelId) ?? DEFAULT_LEVELS[0]
|
||||
const safeId = (DEFAULT_LEVELS.find(l => l.id === levelId)?.id ?? 'bronze') as LevelId
|
||||
const bgs: Record<LevelId, string> = {
|
||||
bronze: 'bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400',
|
||||
silver: 'bg-slate-100 text-slate-600 dark:bg-slate-700 dark:text-slate-300',
|
||||
@@ -223,7 +224,7 @@ function levelBadge(levelId: LevelId) {
|
||||
platinum: 'bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400',
|
||||
}
|
||||
return (
|
||||
<span className={cn('inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold', bgs[levelId])}>
|
||||
<span className={cn('inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold', bgs[safeId])}>
|
||||
<level.icon size={10} />
|
||||
{level.name}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user