Add collaborator by username

This commit is contained in:
thiloho
2024-08-31 22:55:04 +02:00
parent 6c287cba46
commit 187287ec4f
3 changed files with 36 additions and 13 deletions

View File

@@ -28,6 +28,15 @@ export const actions: Actions = {
addCollaborator: async ({ request, fetch, cookies, params }) => {
const data = await request.formData();
const userData = await fetch(`${API_BASE_PREFIX}/user?username=eq.${data.get("username")}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
}
});
const res = await fetch(`${API_BASE_PREFIX}/collab`, {
method: "POST",
headers: {
@@ -36,7 +45,7 @@ export const actions: Actions = {
},
body: JSON.stringify({
website_id: params.websiteId,
user_id: data.get("user-id"),
user_id: (await userData.json()).id,
permission_level: data.get("permission-level")
})
});

View File

@@ -35,15 +35,8 @@
}}
>
<label>
User id:
<input
type="text"
name="user-id"
minlength="36"
maxlength="36"
placeholder="00000000-0000-0000-0000-000000000000"
required
/>
Username:
<input type="text" name="username" minlength="3" maxlength="16" required />
</label>
<label>