Join tablo forwards to the details

This commit is contained in:
Arthur Belleville 2025-10-24 17:56:45 +02:00
parent b31a40415a
commit 3866262fc3
No known key found for this signature in database
4 changed files with 54 additions and 36 deletions

View file

@ -6,7 +6,11 @@ import type { StreamChat } from "stream-chat";
import { config } from "./config.js";
import type { Tables } from "./database.types.ts";
import { writeCalendarFileToR2 } from "./helpers.js";
import { authMiddleware, r2Middleware, streamChatMiddleware } from "./middleware.js";
import {
authMiddleware,
r2Middleware,
streamChatMiddleware,
} from "./middleware.js";
import { generateToken } from "./token.js";
import { transporter } from "./transporter.js";
import type { EventInsertInTablo, TabloInsert } from "./types.ts";
@ -166,7 +170,9 @@ tabloRouter.post("/create-and-invite", async (c) => {
const { data: insertedTablo, error } = await supabase
.from("tablos")
.insert({
name: `${invitedUserDataTyped.name || "Invité"} / ${ownerDataTyped.name || "Propriétaire"}`,
name: `${invitedUserDataTyped.name || "Invité"} / ${
ownerDataTyped.name || "Propriétaire"
}`,
color: "bg-blue-500",
status: "todo",
owner_id: ownerId,
@ -184,20 +190,22 @@ tabloRouter.post("/create-and-invite", async (c) => {
}
// Grant access to the current user (invited user) as a non-admin member
const { error: tabloAccessError } = await supabase.from("tablo_access").insert(
{
tablo_id: tabloData.id,
user_id: user.id,
// ** IMPORTANT **
is_admin: false,
// -------------
is_active: true,
granted_by: ownerId,
}
// {
// onConflict: "tablo_id, user_id",
// }
);
const { error: tabloAccessError } = await supabase
.from("tablo_access")
.insert(
{
tablo_id: tabloData.id,
user_id: user.id,
// ** IMPORTANT **
is_admin: false,
// -------------
is_active: true,
granted_by: ownerId,
}
// {
// onConflict: "tablo_id, user_id",
// }
);
if (tabloAccessError) {
console.error("tabloAccessError", tabloAccessError);
@ -290,7 +298,8 @@ tabloRouter.patch("/update", async (c) => {
const updatedTablo = update as Tables<"tablos">;
const isUpdatingName = tablo.name !== undefined && tablo.name !== updatedTablo.name;
const isUpdatingName =
tablo.name !== undefined && tablo.name !== updatedTablo.name;
if (error) {
return c.json({ error: error.message }, 500);
@ -335,7 +344,10 @@ tabloRouter.delete("/delete", async (c) => {
.single();
if (accessError || !tabloAccess || !tabloAccess.is_admin) {
return c.json({ error: "You are not authorized to delete this tablo" }, 403);
return c.json(
{ error: "You are not authorized to delete this tablo" },
403
);
}
if (error) {
@ -376,7 +388,10 @@ tabloRouter.post("/invite", async (c) => {
}
if (tablo.owner_id !== sender.id) {
return c.json({ error: "You are not allowed to invite users to this tablo" }, 400);
return c.json(
{ error: "You are not allowed to invite users to this tablo" },
400
);
}
const { data: introConfigData, error: introError } = await supabase
@ -410,8 +425,8 @@ tabloRouter.post("/invite", async (c) => {
<p>Cliquez sur <a href="${
config.XTABLO_URL
}/join/${encodeURIComponent(tablo.name)}?token=${encodeURIComponent(
token
)}">ce lien</a> pour accepter l'invitation.</p>
token
)}">ce lien</a> pour accepter l'invitation.</p>
<br>
<p>Cordialement.</p>
`,
@ -447,15 +462,17 @@ tabloRouter.post("/join", async (c) => {
const { id: invite_id, tablo_id, invited_by } = inviteData;
const { error: tabloAccessError } = await supabase.from("tablo_access").insert({
tablo_id,
user_id: joiner.id,
// ** IMPORTANT **
is_admin: false,
// -------------
is_active: true,
granted_by: invited_by,
});
const { error: tabloAccessError } = await supabase
.from("tablo_access")
.insert({
tablo_id,
user_id: joiner.id,
// ** IMPORTANT **
is_admin: false,
// -------------
is_active: true,
granted_by: invited_by,
});
if (tabloAccessError) {
console.error("tabloAccessError", tabloAccessError);
@ -471,7 +488,7 @@ tabloRouter.post("/join", async (c) => {
console.error("error adding member to channel", error);
}
return c.json({ message: "Tablo joined successfully" });
return c.json({ tablo_id });
});
tabloRouter.get("/members/:tablo_id", async (c) => {

View file

@ -31,7 +31,7 @@ export const useInviteUser = () => {
export const useJoinTablo = () => {
const api = useAuthedApi();
const { mutate } = useMutation({
const { mutate } = useMutation<{ tablo_id: string }, unknown, { token: string }>({
mutationFn: async ({ token }: { token: string }) => {
const { data } = await api.post("/api/v1/tablos/join", { token });
return data;

View file

@ -53,14 +53,15 @@ export const JoinPage = () => {
joinTablo(
{ token },
{
onSuccess: () => {
navigate("/");
onSuccess: ({ tablo_id }) => {
navigate(`/tablos/${tablo_id}`);
},
onError: (error) => {
console.error(error);
toast.add(
{
title: "Erreur",
description: error.message,
description: "Une erreur est survenue.",
type: "error",
},
{ timeout: 2000 }

File diff suppressed because one or more lines are too long