flotilla/src/app/components/SpaceAuthError.svelte

78 lines
2.5 KiB
Svelte
Raw Normal View History

2024-11-19 04:31:17 +00:00
<script lang="ts">
2024-12-30 23:36:54 +00:00
import {displayRelayUrl} from "@welshman/util"
import {parse, renderAsHtml} from "@welshman/content"
2024-11-19 04:31:17 +00:00
import Button from "@lib/components/Button.svelte"
2025-09-10 22:26:39 +00:00
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
2024-11-19 04:31:17 +00:00
import Icon from "@lib/components/Icon.svelte"
2025-02-04 03:28:29 +00:00
import {preventDefault} from "@lib/html"
import {ucFirst} from "@lib/util"
2026-01-30 22:14:12 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
2024-11-19 04:31:17 +00:00
import ModalHeader from "@lib/components/ModalHeader.svelte"
2026-02-02 18:09:14 +00:00
import ModalTitle from "@lib/components/ModalTitle.svelte"
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
2024-11-19 04:31:17 +00:00
import ModalFooter from "@lib/components/ModalFooter.svelte"
import SpaceAccessRequest from "@app/components/SpaceAccessRequest.svelte"
import {leaveSpace} from "@app/access"
import {clearModals, navigate, pushModal} from "@app/modal"
import {pushToast} from "@app/toast"
2024-11-19 04:31:17 +00:00
2026-07-28 16:16:26 +00:00
type Props = {
url: string
error: string
}
const {url, error}: Props = $props()
2024-11-19 04:31:17 +00:00
const back = () => navigate("/home")
2024-11-19 04:31:17 +00:00
2026-01-30 16:41:58 +00:00
const requestAccess = () => pushModal(SpaceAccessRequest, {url, callback: clearModals})
2025-11-05 23:09:23 +00:00
const leave = async () => {
2025-11-05 23:09:23 +00:00
loading = true
try {
await leaveSpace(url)
await navigate("/home")
} catch (e) {
console.error(e)
pushToast({theme: "error", message: "Failed to leave the space."})
2025-11-05 23:09:23 +00:00
} finally {
loading = false
}
}
let loading = $state(false)
2024-11-19 04:31:17 +00:00
</script>
2026-01-30 22:14:12 +00:00
<Modal tag="form" onsubmit={preventDefault(requestAccess)}>
<ModalBody>
<ModalHeader>
2026-02-02 18:09:14 +00:00
<ModalTitle>Access Error</ModalTitle>
<ModalSubtitle>We couldn't connect you to this space.</ModalSubtitle>
2026-01-30 22:14:12 +00:00
</ModalHeader>
<p>
We received an error from the relay indicating you don't have access to {displayRelayUrl(
url,
)}:
</p>
<p class="card welshman-content">
2026-01-30 22:14:12 +00:00
{@html renderAsHtml(parse({content: ucFirst(error)}))}
</p>
</ModalBody>
2024-11-19 04:31:17 +00:00
<ModalFooter>
<Button class="button button-link" onclick={back}>
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowLeft} />
Go Home
2024-11-19 04:31:17 +00:00
</Button>
2025-11-05 23:09:23 +00:00
<div class="flex gap-2">
<Button class="button button-error" onclick={leave} disabled={loading}>Leave Space</Button>
<Button type="submit" class="button button-primary" disabled={loading}>
2025-11-05 23:09:23 +00:00
Request Access
<Icon icon={AltArrowRight} />
</Button>
</div>
2024-11-19 04:31:17 +00:00
</ModalFooter>
2026-01-30 22:14:12 +00:00
</Modal>