|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, ref } from "vue"; |
| 3 | +import { useI18n } from "vue-i18n"; |
| 4 | +import { CheckCircle2, Link, Unlink } from "lucide-vue-next"; |
| 5 | +import { DiscordLogoIcon } from "@radix-icons/vue"; |
| 6 | +import { Button } from "~/components/ui/button"; |
| 7 | +import { toast } from "~/components/ui/toast"; |
| 8 | +import { |
| 9 | + AlertDialog, |
| 10 | + AlertDialogCancel, |
| 11 | + AlertDialogContent, |
| 12 | + AlertDialogDescription, |
| 13 | + AlertDialogFooter, |
| 14 | + AlertDialogHeader, |
| 15 | + AlertDialogTitle, |
| 16 | +} from "~/components/ui/alert-dialog"; |
| 17 | +import FiveStackToolTip from "~/components/FiveStackToolTip.vue"; |
| 18 | +import FadeSwap from "~/components/ui/transitions/FadeSwap.vue"; |
| 19 | +import { generateMutation } from "~/graphql/graphqlGen"; |
| 20 | +
|
| 21 | +const { t } = useI18n(); |
| 22 | +
|
| 23 | +const linked = computed(() => useAuthStore().hasDiscordLinked); |
| 24 | +
|
| 25 | +const showUnlinkConfirm = ref(false); |
| 26 | +const unlinking = ref(false); |
| 27 | +
|
| 28 | +function linkDiscord() { |
| 29 | + window.location.href = `https://${useRuntimeConfig().public.webDomain}/auth/discord?redirect=${encodeURIComponent(window.location.toString())}`; |
| 30 | +} |
| 31 | +
|
| 32 | +async function confirmUnlink() { |
| 33 | + if (unlinking.value) { |
| 34 | + return; |
| 35 | + } |
| 36 | + unlinking.value = true; |
| 37 | + try { |
| 38 | + const { $apollo } = useNuxtApp(); |
| 39 | + await ($apollo as any).mutate({ |
| 40 | + mutation: generateMutation({ |
| 41 | + unlinkDiscord: { success: true }, |
| 42 | + }), |
| 43 | + }); |
| 44 | + showUnlinkConfirm.value = false; |
| 45 | + await useAuthStore().getMe(); |
| 46 | + toast({ title: t("pages.settings.account.discord.unlinked") }); |
| 47 | + } finally { |
| 48 | + unlinking.value = false; |
| 49 | + } |
| 50 | +} |
| 51 | +</script> |
| 52 | + |
| 53 | +<template> |
| 54 | + <FadeSwap> |
| 55 | + <div |
| 56 | + v-if="linked" |
| 57 | + key="linked" |
| 58 | + class="rounded-lg border border-border bg-card/50 overflow-hidden" |
| 59 | + > |
| 60 | + <div class="flex items-center justify-between gap-3 px-4 py-3"> |
| 61 | + <div class="flex items-center gap-2.5 min-w-0"> |
| 62 | + <span |
| 63 | + class="shrink-0 w-7 h-7 rounded-md flex items-center justify-center bg-emerald-500/15 text-emerald-400" |
| 64 | + > |
| 65 | + <CheckCircle2 class="w-4 h-4" /> |
| 66 | + </span> |
| 67 | + <div class="min-w-0"> |
| 68 | + <div class="text-sm font-medium leading-tight"> |
| 69 | + {{ $t("pages.settings.account.discord.title") }} |
| 70 | + </div> |
| 71 | + <div class="text-xs text-muted-foreground"> |
| 72 | + {{ $t("pages.settings.account.discord.linked") }} |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + |
| 77 | + <FiveStackToolTip side="bottom"> |
| 78 | + <template #trigger> |
| 79 | + <Button |
| 80 | + size="icon" |
| 81 | + variant="ghost" |
| 82 | + class="h-8 w-8 shrink-0 text-muted-foreground hover:text-destructive hover:bg-destructive/10 [&_svg]:size-3.5" |
| 83 | + :aria-label="$t('pages.settings.account.discord.unlink')" |
| 84 | + @click="showUnlinkConfirm = true" |
| 85 | + > |
| 86 | + <Unlink /> |
| 87 | + </Button> |
| 88 | + </template> |
| 89 | + {{ $t("pages.settings.account.discord.unlink") }} |
| 90 | + </FiveStackToolTip> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + |
| 94 | + <div |
| 95 | + v-else |
| 96 | + key="unlinked" |
| 97 | + class="rounded-lg border border-border bg-card/50 overflow-hidden" |
| 98 | + > |
| 99 | + <div class="flex items-center justify-between gap-3 px-4 py-3"> |
| 100 | + <div class="flex items-center gap-2.5 min-w-0"> |
| 101 | + <span |
| 102 | + class="shrink-0 w-7 h-7 rounded-md flex items-center justify-center bg-muted text-muted-foreground" |
| 103 | + > |
| 104 | + <DiscordLogoIcon class="w-4 h-4" /> |
| 105 | + </span> |
| 106 | + <div class="min-w-0"> |
| 107 | + <div class="text-sm font-medium leading-tight"> |
| 108 | + {{ $t("pages.settings.account.discord.title") }} |
| 109 | + </div> |
| 110 | + <div class="text-xs text-muted-foreground"> |
| 111 | + {{ $t("pages.settings.account.discord.description") }} |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + |
| 116 | + <Button |
| 117 | + variant="outline" |
| 118 | + size="sm" |
| 119 | + class="shrink-0" |
| 120 | + @click="linkDiscord" |
| 121 | + > |
| 122 | + <Link /> |
| 123 | + {{ $t("pages.settings.account.discord.link") }} |
| 124 | + </Button> |
| 125 | + </div> |
| 126 | + </div> |
| 127 | + </FadeSwap> |
| 128 | + |
| 129 | + <AlertDialog v-model:open="showUnlinkConfirm"> |
| 130 | + <AlertDialogContent> |
| 131 | + <AlertDialogHeader> |
| 132 | + <AlertDialogTitle>{{ |
| 133 | + $t("pages.settings.account.discord.unlink_dialog.title") |
| 134 | + }}</AlertDialogTitle> |
| 135 | + <AlertDialogDescription> |
| 136 | + {{ $t("pages.settings.account.discord.unlink_dialog.description") }} |
| 137 | + </AlertDialogDescription> |
| 138 | + </AlertDialogHeader> |
| 139 | + <AlertDialogFooter> |
| 140 | + <AlertDialogCancel :disabled="unlinking">{{ |
| 141 | + $t("common.cancel") |
| 142 | + }}</AlertDialogCancel> |
| 143 | + <Button |
| 144 | + variant="destructive" |
| 145 | + :loading="unlinking" |
| 146 | + @click="confirmUnlink" |
| 147 | + > |
| 148 | + {{ $t("pages.settings.account.discord.unlink_dialog.confirm") }} |
| 149 | + </Button> |
| 150 | + </AlertDialogFooter> |
| 151 | + </AlertDialogContent> |
| 152 | + </AlertDialog> |
| 153 | +</template> |
0 commit comments