chahinebrini 5434254f74 feat(auth,mail): pw-reset OTP-flow + custom mail templates + account-switch cleanup
- Phase 3 PW-Reset: 3 screens (forgot-password → reset-otp → new-password),
  verifyOtp({type:'recovery'}), new updatePassword() action
- Custom Brevo-Mail templates (backend/public/templates/) — 5 HTMLs with
  go-template i18n (de/en/fr/ar incl. RTL for AR), OTP-only (no link),
  ReBreak branding
- signUp metadata.data.locale aus i18n.language → templates resolven Sprache
- Account-Switch-Bug fix: signOut() resettet alle 10 user-spezifischen stores
  + invalidateMe()
2026-05-19 10:49:23 +02:00

110 lines
3.0 KiB
TypeScript

import { create } from 'zustand';
export type CommunityCategory = 'all' | 'games' | 'domain_vote' | 'lyra' | 'rebreak';
export interface CommunityPostAuthor {
id: string | null;
username: string;
nickname: string;
avatar: string | null;
plan: string;
tier?: string;
}
export interface CommunityPost {
id: string;
category: string;
content: string;
imageUrl?: string | null;
likesCount: number;
dislikesCount: number;
commentsCount: number;
repostsCount: number;
isAnonymous: boolean;
createdAt: string;
userLike: 'like' | 'dislike' | null;
isBot?: boolean;
botType?: 'lyra' | 'rebreak';
gameName?: string | null;
challengeId?: string | null;
challengeStatus?: 'OPEN' | 'ACTIVE' | 'FINISHED' | 'CANCELLED' | null;
opponentName?: string | null;
isLive?: boolean;
i18nKey?: string | null;
userVote?: 'yes' | 'no' | null;
submission?: {
id: string;
domain: string;
status: 'pending' | 'approved' | 'rejected' | 'in_review';
yesVotes: number;
noVotes: number;
reviewedAt?: string | null;
yesVoters?: Array<{ id: string; nickname: string; avatar: string | null }>;
noVoters?: Array<{ id: string; nickname: string; avatar: string | null }>;
} | null;
author: CommunityPostAuthor;
repostOf?: {
author: CommunityPostAuthor;
content: string;
imageUrl?: string | null;
} | null;
}
export interface CommunityComment {
id: string;
content: string;
createdAt: string;
parentCommentId: string | null;
authorNickname: string;
authorAvatar: string | null;
authorId: string | null;
likesCount: number;
userLike: boolean;
}
type CommunityState = {
activeCategory: CommunityCategory;
setCategory: (cat: CommunityCategory) => void;
optimisticLikes: Record<string, { delta: number; userLike: 'like' | null }>;
applyOptimisticLike: (postId: string, currentLike: 'like' | null, currentCount: number) => { newLike: 'like' | null; newCount: number };
revertOptimisticLike: (postId: string) => void;
clearOptimisticLike: (postId: string) => void;
reset: () => void;
};
export const useCommunityStore = create<CommunityState>((set, get) => ({
activeCategory: 'all',
optimisticLikes: {},
setCategory: (cat) => set({ activeCategory: cat }),
applyOptimisticLike: (postId, currentLike, currentCount) => {
const isLiked = currentLike === 'like';
const newLike: 'like' | null = isLiked ? null : 'like';
const newCount = isLiked ? Math.max(0, currentCount - 1) : currentCount + 1;
set((s) => ({
optimisticLikes: {
...s.optimisticLikes,
[postId]: { delta: newCount - currentCount, userLike: newLike },
},
}));
return { newLike, newCount };
},
revertOptimisticLike: (postId) => {
set((s) => {
const { [postId]: _, ...rest } = s.optimisticLikes;
return { optimisticLikes: rest };
});
},
clearOptimisticLike: (postId) => {
set((s) => {
const { [postId]: _, ...rest } = s.optimisticLikes;
return { optimisticLikes: rest };
});
},
reset: () => set({ activeCategory: 'all', optimisticLikes: {} }),
}));