Allow posting announcements with other metadata

This commit is contained in:
Tusooa Zhu 2022-03-17 15:45:45 -04:00 committed by tusooa
parent db5c0c3502
commit 56e6d86f88
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
3 changed files with 40 additions and 4 deletions

View file

@ -1,14 +1,19 @@
import { mapState } from 'vuex'
import Announcement from '../announcement/announcement.vue'
import Checkbox from '../checkbox/checkbox.vue'
const AnnouncementsPage = {
components: {
Announcement
Announcement,
Checkbox
},
data () {
return {
newAnnouncement: {
content: ''
content: '',
startsAt: undefined,
endsAt: undefined,
allDay: false
},
posting: false,
error: undefined
@ -29,6 +34,11 @@ const AnnouncementsPage = {
postAnnouncement () {
this.posting = true
this.$store.dispatch('postAnnouncement', this.newAnnouncement)
.then(() => {
this.newAnnouncement.content = ''
this.startsAt = undefined
this.endsAt = undefined
})
.catch(error => {
this.error = error.error
})

View file

@ -23,6 +23,29 @@
:placeholder="$t('announcements.post_placeholder')"
:disabled="posting"
/>
<span class="announcement-metadata">
<label for="announcement-start-time">{{ $t('announcements.start_time_prompt') }}</label>
<input
id="announcement-start-time"
v-model="newAnnouncement.startsAt"
:type="newAnnouncement.allDay ? 'date' : 'datetime-local'"
>
</span>
<span class="announcement-metadata">
<label for="announcement-end-time">{{ $t('announcements.end_time_prompt') }}</label>
<input
id="announcement-end-time"
v-model="newAnnouncement.endsAt"
:type="newAnnouncement.allDay ? 'date' : 'datetime-local'"
>
</span>
<span class="announcement-metadata">
<Checkbox
id="announcement-all-day"
v-model="newAnnouncement.allDay"
/>
<label for="announcement-all-day">{{ $t('announcements.all_day_prompt') }}</label>
</span>
</div>
<div class="footer">
<button
@ -80,6 +103,9 @@
display: flex;
align-items: stretch;
flex-direction: column;
.announcement-metadata {
margin-top: 0.5em;
}
}
.post-textarea {

View file

@ -1381,11 +1381,11 @@ const postAnnouncement = ({ credentials, content, startsAt, endsAt, allDay }) =>
const payload = { content }
if (typeof startsAt !== 'undefined') {
payload['starts_at'] = startsAt
payload['starts_at'] = new Date(startsAt).toISOString()
}
if (typeof endsAt !== 'undefined') {
payload['ends_at'] = endsAt
payload['ends_at'] = new Date(endsAt).toISOString()
}
if (typeof allDay !== 'undefined') {