You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.5 KiB
79 lines
2.5 KiB
<script> |
|
import { onMount } from 'svelte'; |
|
import { t } from '../../translations.svelte.js'; |
|
import { useTinyRouter } from 'svelte-tiny-router'; |
|
|
|
let { serviceName } = $props(); |
|
let service = $state({}) |
|
let caption = $state(t('user.save_service')); |
|
let message = $state(t('user.loading_data')); |
|
let router = useTinyRouter(); |
|
let disabled = $state(false); |
|
|
|
onMount(async () => { |
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`; |
|
const resp = await fetch(url,{credentials:'include'}); |
|
if (resp.ok){ |
|
const json = await resp.json(); |
|
for (let key of Object.keys(json)) service[key] = json[key]; |
|
} else { |
|
message = await resp.text(); |
|
if (!message) message = t(resp); |
|
} |
|
}); |
|
|
|
async function update(){ |
|
caption = t('user.data_sent'); |
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`; |
|
const resp = await fetch(url,{ |
|
credentials: 'include', |
|
method: 'PATCH', |
|
body: JSON.stringify(service) |
|
}); |
|
if (resp.ok){ |
|
caption = t('user.saved'); |
|
router.navigate('/user'); |
|
} else { |
|
caption = await resp.text(); |
|
if (!caption) caption = t(resp); |
|
} |
|
} |
|
</script> |
|
|
|
<fieldset> |
|
<legend>{t('user.edit_service',serviceName)}</legend> |
|
{#if service.name || !serviceName} |
|
<table> |
|
<tbody> |
|
<tr> |
|
<th>{t('user.name')}</th> |
|
<td> |
|
<input type="text" bind:value={service.name} /> |
|
</td> |
|
</tr> |
|
<tr> |
|
<th>{t('user.client_id')}</th> |
|
<td> |
|
<input type="text" bind:value={service.client_id} /> |
|
</td> |
|
</tr> |
|
<tr> |
|
<th>{t('user.client_secret')}</th> |
|
<td> |
|
<input type="text" bind:value={service.client_secret} /> |
|
</td> |
|
</tr> |
|
<tr> |
|
<th>{t('user.base_url')}</th> |
|
<td> |
|
<input type="text" bind:value={service.url} /> |
|
</td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
<button onclick={update} {disabled}>{caption}</button> |
|
<button onclick={() => router.navigate('/user')} {disabled}>{t('user.abort')}</button> |
|
{:else} |
|
{message} |
|
{/if} |
|
</fieldset> |