Reimplemented outdated code, added encryption keys for each room, added support for profile images, added friend requests via url/qr-code
This commit is contained in:
1 parent
508f17315e
commit
32e4bf8b32
58 files changed
+3270
-362
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import {
|
||||
createRoom,
|
||||
addMember,
|
||||
deleteRoom,
|
||||
removeMember,
|
||||
} from "@/utils/rooms/rooms";
|
||||
import { UUID_REGEX } from "@/utils/validation";
|
||||
|
||||
export type CreateRoomState = {
|
||||
error?: string;
|
||||
} | null;
|
||||
|
||||
export async function createRoomAction(
|
||||
_prevState: CreateRoomState,
|
||||
formData: FormData,
|
||||
): Promise<CreateRoomState> {
|
||||
const name = formData.get("name");
|
||||
if (typeof name !== "string" || !name.trim()) {
|
||||
return { error: "Room name is required." };
|
||||
}
|
||||
|
||||
const result = await createRoom(name.trim());
|
||||
if (result.error) {
|
||||
return { error: result.error };
|
||||
}
|
||||
|
||||
revalidatePath("/rooms");
|
||||
redirect(`/rooms/${result.roomId}`);
|
||||
}
|
||||
|
||||
export type AddMemberState = {
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
} | null;
|
||||
|
||||
export async function addMemberAction(
|
||||
roomId: string,
|
||||
_prevState: AddMemberState,
|
||||
formData: FormData,
|
||||
): Promise<AddMemberState> {
|
||||
const userId = formData.get("userId");
|
||||
if (typeof userId !== "string" || !userId.trim()) {
|
||||
return { error: "User ID is required." };
|
||||
}
|
||||
|
||||
const trimmed = userId.trim();
|
||||
if (!UUID_REGEX.test(trimmed)) {
|
||||
return { error: "Please enter a valid user ID (UUID format)." };
|
||||
}
|
||||
|
||||
const result = await addMember(roomId, trimmed);
|
||||
if (result.error) {
|
||||
return { error: result.error };
|
||||
}
|
||||
|
||||
revalidatePath("/rooms");
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
export async function deleteRoomAction(roomId: string) {
|
||||
const result = await deleteRoom(roomId);
|
||||
if (result.error) {
|
||||
return { error: result.error };
|
||||
}
|
||||
|
||||
revalidatePath("/rooms");
|
||||
redirect("/rooms");
|
||||
}
|
||||
|
||||
export async function removeMemberAction(roomId: string, userId: string) {
|
||||
const result = await removeMember(roomId, userId);
|
||||
if (result.error) {
|
||||
return { error: result.error };
|
||||
}
|
||||
|
||||
revalidatePath(`/rooms/${roomId}`);
|
||||
return { success: true };
|
||||
}
|
||||
Reference in new issue
Block a user