feat: create Modal component, rename InvitePopup to InviteModal and add invite generation

This commit is contained in:
SauceyRed 2025-07-07 11:35:16 +02:00
parent a551cd547d
commit 21cb1c37df
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462
2 changed files with 41 additions and 33 deletions

View file

@ -1,13 +1,15 @@
<template>
<div id="invite-popup">
<div v-if="invite">
<p>{{ invite }}</p>
<button @click="copyInvite">Copy Link</button>
<Modal title="Create an invite">
<div id="invite-popup">
<div v-if="invite">
<p>{{ invite }}</p>
<button @click="copyInvite">Copy Link</button>
</div>
<div v-else>
<button @click="generateInvite">Generate Invite</button>
</div>
</div>
<div v-else>
<button @click="generateInvite">Generate Invite</button>
</div>
</div>
</Modal>
</template>
<script lang="ts" setup>
@ -19,9 +21,14 @@ const invite = ref<string>();
const route = useRoute();
async function generateInvite(): Promise<void> {
const chars = "ABCDEFGHIJKLMNOQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
let randCode = "";
for (let i = 0; i < 6; i++) {
randCode += chars[Math.floor(Math.random() * chars.length)];
}
const createdInvite: InviteResponse | undefined = await fetchWithApi(
`/guilds/${route.params.serverId}/invites`,
{ method: "POST", body: { custom_id: "oijewfoiewf" } }
{ method: "POST", body: { custom_id: randCode } }
);
invite.value = createdInvite?.id;

View file

@ -1,41 +1,39 @@
<template>
<div class="modal-top-container">
<div v-if="heavy" class="modal-container modal-heavy">
</div>
<div v-else class="modal-container modal-light">
</div>
<div class="modal-div">
<slot />
</div>
</div>
<dialog ref="dialog" class="modal">
<h1 class="modal-title">{{ title }}</h1>
<slot />
</dialog>
</template>
<script lang="ts" setup>
const props = defineProps<{ heavy?: boolean }>();
const props = defineProps<{ title: string, heavy?: boolean }>();
const dialog = ref<HTMLDialogElement>();
onMounted(() => {
if (dialog) {
dialog.value?.showModal();
}
});
</script>
<style>
.modal-container {
position: fixed;
border: 1px solid cyan;
height: 100%;
width: 100%;
opacity: 70%;
z-index: 10;
background-color: var(--background-color);
}
.modal-div {
.modal {
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(50, 50, 50);
flex-direction: column;
opacity: 100%;
z-index: 11;
padding: 1%;
background-color: var(--background-color);
color: var(--main-text-color);
}
.modal::backdrop {
background-color: rgb(50, 50, 50);
opacity: 70%;
}
.modal-top-container {
@ -47,4 +45,7 @@ const props = defineProps<{ heavy?: boolean }>();
width: 100%;
}
.modal-title {
font-size: 1.5rem;
}
</style>