From c5e801a45fe855b6f12aca9a506f236fc4e7193e Mon Sep 17 00:00:00 2001 From: James Collins Date: Wed, 25 Jan 2023 11:55:49 +1000 Subject: [PATCH] fix date picker initial content --- resources/js/components/SMDatePicker.vue | 5 ++++- resources/js/views/dashboard/EventEdit.vue | 1 - resources/js/views/dashboard/PostEdit.vue | 10 ++++++++-- resources/js/views/dashboard/PostList.vue | 4 ++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/resources/js/components/SMDatePicker.vue b/resources/js/components/SMDatePicker.vue index 6de1ba2..44ced68 100644 --- a/resources/js/components/SMDatePicker.vue +++ b/resources/js/components/SMDatePicker.vue @@ -124,7 +124,10 @@ const computedEnableTime = computed(() => { }); watch(initialContent, (newContent) => { - if (typeof date.value == "undefined") { + if ( + typeof date.value == "undefined" || + (typeof date.value == "string" && date.value.length == 0) + ) { date.value = newContent === undefined ? "" : newContent; } }); diff --git a/resources/js/views/dashboard/EventEdit.vue b/resources/js/views/dashboard/EventEdit.vue index 93afac0..0b911a0 100644 --- a/resources/js/views/dashboard/EventEdit.vue +++ b/resources/js/views/dashboard/EventEdit.vue @@ -162,7 +162,6 @@ import { restParseErrors, } from "../../helpers/validation"; import { useRoute } from "vue-router"; -import { formatAusDateToUniversal } from "../../helpers/common"; import { parseISO } from "date-fns"; const route = useRoute(); diff --git a/resources/js/views/dashboard/PostEdit.vue b/resources/js/views/dashboard/PostEdit.vue index f5a339a..f3f6e48 100644 --- a/resources/js/views/dashboard/PostEdit.vue +++ b/resources/js/views/dashboard/PostEdit.vue @@ -135,8 +135,11 @@ const formData = reactive({ }, }, publish_at: { - value: "", + value: null, error: "", + rules: { + datetime: true, + }, }, hero: { value: "", @@ -200,11 +203,14 @@ const loadData = async () => { throw new Error("The server is currently not available"); } + console.log(res.data.post); formData.title.value = res.data.post.title; formData.slug.value = res.data.post.slug; formData.user_id.value = res.data.post.user_id; formData.content.value = res.data.post.content; - formData.publish_at.value = res.data.post.publish_at; + formData.publish_at.value = res.data.post.publish_at + ? new Date(res.data.post.publish_at) + : ""; formData.content.value = res.data.post.content; formData.hero.value = res.data.post.hero; } catch (err) { diff --git a/resources/js/views/dashboard/PostList.vue b/resources/js/views/dashboard/PostList.vue index c1ae3a1..13cddf6 100644 --- a/resources/js/views/dashboard/PostList.vue +++ b/resources/js/views/dashboard/PostList.vue @@ -68,6 +68,7 @@ const search = ref(""); const headers = [ { text: "Title", value: "title", sortable: true }, + { text: "Published", value: "publish_at", sortable: true }, { text: "Created", value: "created_at", sortable: true }, { text: "Updated", value: "updated_at", sortable: true }, { text: "Actions", value: "actions" }, @@ -127,6 +128,9 @@ const loadFromServer = async () => { if (row.updated_at !== "undefined") { row.updated_at = relativeDate(row.updated_at); } + if (row.publish_at !== "undefined") { + row.publish_at = relativeDate(row.publish_at); + } }); serverItemsLength.value = res.data.total;