flotilla/src/app/components/hosting/RelayCreate.svelte

33 lines
1.2 KiB
Svelte
Raw Normal View History

2026-07-15 16:30:17 +00:00
<script lang="ts">
2026-07-28 16:16:26 +00:00
import {publish} from "@welshman/app"
2026-07-15 16:30:17 +00:00
import RelayForm, {type RelayFormValues} from "@app/components/hosting/RelayForm.svelte"
import PaymentDialog from "@app/components/hosting/PaymentDialog.svelte"
import PaymentSetup from "@app/components/hosting/PaymentSetup.svelte"
import {roomLists} from "@app/core"
import {navigate, pushModal} from "@app/modal"
2026-07-15 16:30:17 +00:00
import {makeSpacePath} from "@app/routes"
import {createHostedRelay, getHostedRelayUrl, hosting, isPaidPlan} from "@app/hosting"
2026-07-15 16:30:17 +00:00
const submit = async (values: RelayFormValues) => {
const relay = await createHostedRelay(values)
2026-07-15 16:30:17 +00:00
const url = getHostedRelayUrl(relay)
$hosting.setRelay(relay)
// Join the space now, or the space layout prompts for it and displaces the payment modals.
2026-07-28 16:16:26 +00:00
await $roomLists.addRelay(url).then(publish)
2026-07-15 16:30:17 +00:00
const due = isPaidPlan(values.plan_id) ? await $hosting.findPaymentDue() : undefined
2026-07-15 16:30:17 +00:00
await navigate(makeSpacePath(url, "admin"), {replaceState: true})
2026-07-15 16:30:17 +00:00
if (due?.invoice) {
pushModal(PaymentDialog, {invoice: due.invoice})
} else if (due) {
pushModal(PaymentSetup)
2026-07-15 16:30:17 +00:00
}
}
</script>
<RelayForm mode="create" submitLabel="Create Space" onSubmit={submit} />