2026-06-22 20:36:57 +00:00
|
|
|
<script lang="ts">
|
2026-07-28 16:16:26 +00:00
|
|
|
import type {RelayRoleReader} from "@welshman/domain"
|
|
|
|
|
import {makeRelayRoleKey} from "@welshman/app"
|
2026-06-22 20:36:57 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
|
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
|
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
|
|
|
|
import RelayName from "@app/components/RelayName.svelte"
|
|
|
|
|
import RoleForm, {type Values} from "@app/components/RoleForm.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {relayManagement, relayRoles} from "@app/core"
|
2026-06-22 20:36:57 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
url: string
|
2026-07-28 16:16:26 +00:00
|
|
|
role: RelayRoleReader
|
2026-06-22 20:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, role}: Props = $props()
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const id = role.identifier() ?? ""
|
2026-06-22 20:36:57 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const initialValues = {
|
|
|
|
|
label: role.label() ?? "",
|
|
|
|
|
description: role.description() ?? "",
|
|
|
|
|
color: role.color(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const back = () => history.back()
|
2026-06-22 20:36:57 +00:00
|
|
|
|
|
|
|
|
const onSubmit = async ({label, description, color}: Values) => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement
|
|
|
|
|
.forUrl(url)
|
2026-08-21 21:11:13 +00:00
|
|
|
.editRole(id, label, description, color, role.order())
|
2026-06-22 20:36:57 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
2026-07-28 16:16:26 +00:00
|
|
|
// Pull the relay's freshly-signed role event so the UI reflects the change
|
|
|
|
|
// immediately, rather than waiting for the live subscription to catch up.
|
|
|
|
|
await $relayRoles.forceLoad(makeRelayRoleKey(url, id))
|
|
|
|
|
|
2026-06-22 20:36:57 +00:00
|
|
|
pushToast({message: "Role updated!"})
|
|
|
|
|
back()
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-28 16:16:26 +00:00
|
|
|
|
|
|
|
|
let loading = $state(false)
|
2026-06-22 20:36:57 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
<ModalTitle>Edit Role</ModalTitle>
|
|
|
|
|
<ModalSubtitle>in <RelayName {url} class="text-primary" /></ModalSubtitle>
|
|
|
|
|
</ModalHeader>
|
2026-07-28 16:16:26 +00:00
|
|
|
<RoleForm {loading} {onSubmit} {initialValues} />
|
2026-06-22 20:36:57 +00:00
|
|
|
</ModalBody>
|
|
|
|
|
</Modal>
|