-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add admin UserRole and add API to set it. * Make basic user page * Add Make Admin button * fix build and lint * DRY up requests.ts * Don't watchEffect in a click handler * react to successful setRole * Address feedback on user ID API * lint
- Loading branch information
1 parent
dcfe2d5
commit c53b04a
Showing
7 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
import { UserResponse, UserRole } from "@ogfcommunity/variants-shared"; | ||
import { ref, watchEffect } from "vue"; | ||
import * as requests from "../requests"; | ||
import { useCurrentUser } from "@/stores/user"; | ||
const props = defineProps<{ userId: string }>(); | ||
const user = ref<UserResponse>(); | ||
const err = ref<string>(); | ||
watchEffect(async () => { | ||
try { | ||
user.value = await requests.get(`/users/${props.userId}`); | ||
} catch (e) { | ||
err.value = e as string; | ||
} | ||
}); | ||
const loggedInUser = useCurrentUser(); | ||
function setRole(role: UserRole) { | ||
requests | ||
.put(`/users/${props.userId}/role`, { role }) | ||
.then(() => (user.value = user.value ? { ...user.value, role } : undefined)) | ||
.catch(alert); | ||
} | ||
</script> | ||
|
||
<template> | ||
<main> | ||
<div class="grid-page-layout"> | ||
<div v-if="user"> | ||
<div v-if="user.login_type === 'guest'">Guest User</div> | ||
<div v-else>{{ user.username }}</div> | ||
<div v-if="user.role">{{ user.role }}</div> | ||
<div v-if="loggedInUser?.role === 'admin'"> | ||
<button v-if="user.role !== 'admin'" @click="setRole('admin')"> | ||
Make Admin | ||
</button> | ||
</div> | ||
</div> | ||
<div v-if="err">{{ err }}</div> | ||
</div> | ||
</main> | ||
</template> |