-
Gambar
-
+
+
+
+
+
+
+
+
Gambar tema konten harus diisi
+
@@ -85,6 +94,7 @@
import { required } from '@vuelidate/validators';
import Multiselect from '@suadelabs/vue3-multiselect';
import '@suadelabs/vue3-multiselect/dist/vue3-multiselect.css';
+ import '@/assets/css/file-upload-preview.css';
useHead({ title: 'Daftar Topik Konten' });
@@ -106,6 +116,8 @@
const $validate = useVuelidate(rules, { form });
const router = useRouter();
+ const config = useRuntimeConfig();
+
const params = reactive({
current_page: 1,
pagesize: 10,
@@ -114,7 +126,7 @@
});
const { data: themes } = await useAsyncData('themes',
- () => $fetch('http://localhost:8000/content/themes/', {
+ () => $fetch(`${config.public.apiBase}content/themes/`, {
params: {
page: params.current_page,
page_size: 50
@@ -124,6 +136,19 @@
}
);
+ onMounted(async () => {
+ const fileupload = await import('file-upload-with-preview');
+ let FileUploadWithPreview = fileupload.default;
+
+ // single image upload
+ new FileUploadWithPreview('featuredImage', {
+ images: {
+ baseImage: '/assets/images/file-preview.svg',
+ backgroundImage: '',
+ },
+ });
+ });
+
const submitForm = async () => {
isSubmitted.value = true;
$validate.value.form.$touch();
@@ -131,14 +156,18 @@
return false;
}
- await $fetch('http://localhost:8000/content/topics/', {
+ const formData = new FormData();
+ formData.append('topic', form.value.topic);
+ formData.append('theme', form.value.theme.id);
+ formData.append('description', form.value.description);
+
+ if (form.value.featured_image) {
+ formData.append('featured_image', form.value.featured_image);
+ }
+
+ await $fetch(`${config.public.apiBase}content/topics/`, {
method: 'POST',
- body: {
- "theme": form.value.theme.id,
- "topic": form.value.topic,
- "description": form.value.description,
- "featured_image": form.value.featured_image
- }
+ body: formData
}).then(() => {
//redirect
router.push({ path: "/content/topics/list" });
@@ -149,4 +178,18 @@
console.log(error);
});
}
+
+ function handleImageChange(event: { target: { files: any[]; }; }) {
+ const file = event.target.files[0]
+
+ if (!file) return
+
+ const allowed = ['image/png']
+ if (!allowed.includes(file.type)) {
+ alert('Hanya PNG yang diizinkan')
+ return
+ }
+
+ form.value.featured_image = file
+ }
\ No newline at end of file
diff --git a/pages/content/topics/list.vue b/pages/content/topics/list.vue
index efaf029..fbfd494 100644
--- a/pages/content/topics/list.vue
+++ b/pages/content/topics/list.vue
@@ -67,6 +67,8 @@
const router = useRouter();
+ const config = useRuntimeConfig();
+
const cols =
ref([
{ field: 'topic', title: 'Topik' },
@@ -87,7 +89,7 @@
() => {
console.log('asyncData');
console.log(params);
- return $fetch('http://localhost:8000/content/topics/', {
+ return $fetch(`${config.public.apiBase}/content/topics/`, {
params: {
page: params.current_page,
page_size: params.pagesize,
@@ -119,7 +121,7 @@
const deleteData = async (data: any) => {
//delete data with API
- await $fetch(`http://localhost:8000/content/topics/${data.id}/`, {
+ await $fetch(`${config.public.apiBase}content/topics/${data.id}/`, {
method: 'DELETE'
});