fix: modals not showing properly due to imports not being updated after components folder restructuring
This commit is contained in:
parent
7f1b26a59c
commit
088c6c558b
4 changed files with 6 additions and 5 deletions
70
components/Modal/Invite.vue
Normal file
70
components/Modal/Invite.vue
Normal file
|
@ -0,0 +1,70 @@
|
|||
<template>
|
||||
<ModalBase v-bind="props" :title="props.title || 'Create an invite'">
|
||||
<div v-if="invite" id="invite-body">
|
||||
<div id="invite-label">{{ invite }}</div>
|
||||
<div id="invite-buttons">
|
||||
<Button text="Copy as link" variant="neutral" :callback="() => copyInvite('link')" />
|
||||
<Button text="Copy as code" variant="neutral" :callback="() => copyInvite('code')" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<Button text="Generate Invite" variant="normal" :callback="generateInvite">Generate Invite</Button>
|
||||
</div>
|
||||
</ModalBase>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { InviteResponse, ModalProps } from '~/types/interfaces';
|
||||
import Button from '~/components/UserInterface/Button.vue';
|
||||
|
||||
const props = defineProps<ModalProps & { guildId: string }>();
|
||||
|
||||
const invite = ref<string>();
|
||||
|
||||
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/${props.guildId}/invites`,
|
||||
{ method: "POST", body: { custom_id: randCode } }
|
||||
);
|
||||
|
||||
invite.value = createdInvite?.id;
|
||||
return;
|
||||
}
|
||||
|
||||
function copyInvite(type: "link" | "code") {
|
||||
if (!invite.value) return;
|
||||
|
||||
if (type == "link") {
|
||||
const inviteUrl = URL.parse(`invite/${invite.value}`, `${window.location.protocol}//${window.location.host}`);
|
||||
if (inviteUrl) {
|
||||
navigator.clipboard.writeText(inviteUrl.href);
|
||||
}
|
||||
} else {
|
||||
navigator.clipboard.writeText(invite.value);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
#invite-body, #invite-buttons {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
#invite-body {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#invite-label {
|
||||
text-align: center;
|
||||
color: aquamarine;
|
||||
}
|
||||
|
||||
</style>
|
Loading…
Add table
Add a link
Reference in a new issue