2024-10-02 04:32:59 +00:00
|
|
|
<script>
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { getContext } from 'svelte';
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
2024-11-17 00:51:55 +00:00
|
|
|
import { createNewKnowledge, getKnowledgeBases } from '$lib/apis/knowledge';
|
2024-10-02 04:32:59 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2025-04-01 00:28:25 +00:00
|
|
|
import { knowledge, user } from '$lib/stores';
|
2024-11-16 02:21:41 +00:00
|
|
|
import AccessControl from '../common/AccessControl.svelte';
|
2025-06-25 22:44:45 +00:00
|
|
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
let loading = false;
|
|
|
|
|
|
|
|
|
|
let name = '';
|
|
|
|
|
let description = '';
|
2025-04-11 21:46:02 +00:00
|
|
|
let accessControl = {};
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
const submitHandler = async () => {
|
|
|
|
|
loading = true;
|
|
|
|
|
|
2024-10-04 23:18:44 +00:00
|
|
|
if (name.trim() === '' || description.trim() === '') {
|
|
|
|
|
toast.error($i18n.t('Please fill in all fields.'));
|
|
|
|
|
name = '';
|
|
|
|
|
description = '';
|
|
|
|
|
loading = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-17 04:47:45 +00:00
|
|
|
const res = await createNewKnowledge(
|
|
|
|
|
localStorage.token,
|
|
|
|
|
name,
|
|
|
|
|
description,
|
|
|
|
|
accessControl
|
|
|
|
|
).catch((e) => {
|
2025-01-30 05:56:28 +00:00
|
|
|
toast.error(`${e}`);
|
2024-10-02 04:32:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
2024-10-02 05:45:04 +00:00
|
|
|
toast.success($i18n.t('Knowledge created successfully.'));
|
2024-11-17 00:51:55 +00:00
|
|
|
knowledge.set(await getKnowledgeBases(localStorage.token));
|
2024-10-02 05:45:04 +00:00
|
|
|
goto(`/workspace/knowledge/${res.id}`);
|
2024-10-02 04:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="w-full max-h-full">
|
|
|
|
|
<button
|
|
|
|
|
class="flex space-x-1"
|
|
|
|
|
on:click={() => {
|
2024-10-02 05:45:04 +00:00
|
|
|
goto('/workspace/knowledge');
|
2024-10-02 04:32:59 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center">
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
viewBox="0 0 20 20"
|
|
|
|
|
fill="currentColor"
|
|
|
|
|
class="w-4 h-4"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
fill-rule="evenodd"
|
|
|
|
|
d="M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z"
|
|
|
|
|
clip-rule="evenodd"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=" self-center font-medium text-sm">{$i18n.t('Back')}</div>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<form
|
|
|
|
|
class="flex flex-col max-w-lg mx-auto mt-10 mb-10"
|
|
|
|
|
on:submit|preventDefault={() => {
|
|
|
|
|
submitHandler();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" w-full flex flex-col justify-center">
|
2024-11-05 02:37:53 +00:00
|
|
|
<div class=" text-2xl font-medium font-primary mb-2.5">
|
|
|
|
|
{$i18n.t('Create a knowledge base')}
|
|
|
|
|
</div>
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
<div class="w-full flex flex-col gap-2.5">
|
|
|
|
|
<div class="w-full">
|
2024-11-05 02:37:53 +00:00
|
|
|
<div class=" text-sm mb-2">{$i18n.t('What are you working on?')}</div>
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
<div class="w-full mt-1">
|
|
|
|
|
<input
|
2025-02-16 03:27:25 +00:00
|
|
|
class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
|
2024-10-02 04:32:59 +00:00
|
|
|
type="text"
|
|
|
|
|
bind:value={name}
|
2024-11-05 02:37:53 +00:00
|
|
|
placeholder={$i18n.t('Name your knowledge base')}
|
2024-10-02 04:32:59 +00:00
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
2024-11-05 02:37:53 +00:00
|
|
|
<div class="text-sm mb-2">{$i18n.t('What are you trying to achieve?')}</div>
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
<div class=" w-full mt-1">
|
|
|
|
|
<textarea
|
2025-02-16 03:27:25 +00:00
|
|
|
class="w-full resize-none rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
|
2024-10-02 04:32:59 +00:00
|
|
|
rows="4"
|
|
|
|
|
bind:value={description}
|
2024-11-05 02:37:53 +00:00
|
|
|
placeholder={$i18n.t('Describe your knowledge base and objectives')}
|
2024-10-02 04:32:59 +00:00
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-11-16 02:21:41 +00:00
|
|
|
<div class="mt-2">
|
2024-11-17 04:47:45 +00:00
|
|
|
<div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
|
2025-04-01 00:28:25 +00:00
|
|
|
<AccessControl
|
|
|
|
|
bind:accessControl
|
|
|
|
|
accessRoles={['read', 'write']}
|
|
|
|
|
allowPublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
|
|
|
|
/>
|
2024-11-17 04:47:45 +00:00
|
|
|
</div>
|
2024-11-16 02:21:41 +00:00
|
|
|
</div>
|
|
|
|
|
|
2024-10-02 04:32:59 +00:00
|
|
|
<div class="flex justify-end mt-2">
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
class=" text-sm px-4 py-2 transition rounded-lg {loading
|
|
|
|
|
? ' cursor-not-allowed bg-gray-100 dark:bg-gray-800'
|
|
|
|
|
: ' bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800'} flex"
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={loading}
|
|
|
|
|
>
|
2024-10-02 05:45:04 +00:00
|
|
|
<div class=" self-center font-medium">{$i18n.t('Create Knowledge')}</div>
|
2024-10-02 04:32:59 +00:00
|
|
|
|
|
|
|
|
{#if loading}
|
|
|
|
|
<div class="ml-1.5 self-center">
|
2025-06-25 22:44:45 +00:00
|
|
|
<Spinner />
|
2024-10-02 04:32:59 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|