Files
classroomio/apps/dashboard/src/lib/features/course/components/copy-course-modal.svelte
T

64 lines
2.1 KiB
Svelte
Raw Normal View History

2025-10-29 09:57:29 +01:00
<script lang="ts">
2025-11-01 15:49:29 +01:00
import { preventDefault } from '$lib/utils/functions/svelte';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
import Modal from '$lib/components/Modal/index.svelte';
import TextField from '$lib/components/Form/TextField.svelte';
2025-10-29 09:57:29 +01:00
import TextArea from '$lib/components/Form/TextArea.svelte';
import { copyCourseModal } from '$lib/features/course/utils/store';
import { courseCloneApi } from '$lib/features/course/api';
2025-10-29 09:57:29 +01:00
import { t } from '$lib/utils/functions/translations';
2021-12-30 22:30:30 +02:00
async function createCourse() {
if ($copyCourseModal.isSaving || courseCloneApi.isLoading) return;
2025-10-29 09:57:29 +01:00
await courseCloneApi.clone($copyCourseModal.id, $copyCourseModal.title, $copyCourseModal.description);
2021-12-30 22:30:30 +02:00
}
// Sync loading state with modal store
$effect(() => {
$copyCourseModal.isSaving = courseCloneApi.isLoading;
});
2021-12-30 22:30:30 +02:00
</script>
<Modal
onClose={() => ($copyCourseModal.open = false)}
bind:open={$copyCourseModal.open}
width="w-96"
2025-10-29 09:57:29 +01:00
modalHeading={$t('courses.copy_course.title')}
2021-12-30 22:30:30 +02:00
>
2025-11-01 15:49:29 +01:00
<form onsubmit={preventDefault(createCourse)}>
2021-12-30 22:30:30 +02:00
<TextField
2025-10-29 09:57:29 +01:00
label={$t('courses.copy_course.course_name_label')}
2021-12-30 22:30:30 +02:00
bind:value={$copyCourseModal.title}
autoFocus={true}
2025-10-29 09:57:29 +01:00
placeholder={$t('courses.copy_course.course_name_placeholder')}
2021-12-30 22:30:30 +02:00
className="mb-4"
isRequired={true}
autoComplete={false}
errorMessage={courseCloneApi.errors.title}
2021-12-30 22:30:30 +02:00
/>
2025-10-29 09:57:29 +01:00
<TextArea
label={$t('courses.copy_course.course_description_label')}
bind:value={$copyCourseModal.description}
placeholder={$t('courses.copy_course.course_description_placeholder')}
className="mb-4"
rows={4}
errorMessage={courseCloneApi.errors.description}
2025-10-29 09:57:29 +01:00
/>
{#if courseCloneApi.errors.general}
<div class="mb-4 text-sm text-red-600">{courseCloneApi.errors.general}</div>
{/if}
2025-10-29 09:57:29 +01:00
<div class="mt-5 flex flex-row-reverse items-center">
2021-12-30 22:30:30 +02:00
<PrimaryButton
className="px-6 py-3"
2025-10-29 09:57:29 +01:00
label={$t('courses.copy_course.create_button')}
2021-12-30 22:30:30 +02:00
type="submit"
isLoading={$copyCourseModal.isSaving}
/>
</div>
</form>
</Modal>