Skip to content

Commit

Permalink
Merge pull request #83 from ConductionNL/feature/PC108-117/zaak-add-b…
Browse files Browse the repository at this point in the history
…ericht

finished adding bericht to zaak
  • Loading branch information
RalkeyOfficial authored Dec 6, 2024
2 parents b6b7e8b + cf29be6 commit 3e3f615
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 60 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/entities/zaak/zaak.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const mockZaakData = (): TZaak[] => [
selectielijstklasse: 'http://example.com',
hoofdzaak: 'http://example.com',
klant: '15551d6f-44e3-43f3-a9d2-59e583c91eb0',
berichten: [],
},
]

Expand Down
3 changes: 3 additions & 0 deletions src/entities/zaak/zaak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Zaak implements TZaak {
public selectielijstklasse: string
public hoofdzaak: string
public klant: string
public berichten: string[]

constructor(source: TZaak) {
this.id = source.id || ''
Expand All @@ -51,6 +52,7 @@ export class Zaak implements TZaak {
this.selectielijstklasse = source.selectielijstklasse || ''
this.hoofdzaak = source.hoofdzaak || ''
this.klant = source.klant || ''
this.berichten = source.berichten || []
}

public validate(): SafeParseReturnType<TZaak, unknown> {
Expand Down Expand Up @@ -78,6 +80,7 @@ export class Zaak implements TZaak {
selectielijstklasse: z.string(),
hoofdzaak: z.string(),
klant: z.string(),
berichten: z.array(z.string()),
})

return schema.safeParse(this)
Expand Down
1 change: 1 addition & 0 deletions src/entities/zaak/zaak.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export type TZaak = {
selectielijstklasse: string;
hoofdzaak: string;
klant: string;
berichten: string[];
}
8 changes: 7 additions & 1 deletion src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { navigationStore } from '../store/store.js'
<template>
<!-- Placeholder -->
<div>
<!-- zaak -->
<ZaakForm v-if="navigationStore.modal === 'zaakForm'" />
<ViewZaakAuditTrail v-if="navigationStore.modal === 'viewZaakAuditTrail'" />
<WidgetZaakForm v-if="navigationStore.modal === 'widgetZaakForm'" />
<AddBerichtToZaak v-if="navigationStore.modal === 'addBerichtToZaak'" />
<!-- ==== -->
<EditZaakType />
<EditKlant />
<ViewKlantAuditTrail v-if="navigationStore.modal === 'viewKlantAuditTrail'" />
Expand All @@ -15,7 +19,6 @@ import { navigationStore } from '../store/store.js'
<EditTaak v-if="navigationStore.modal === 'editTaak'" />
<ViewTaakAuditTrail v-if="navigationStore.modal === 'viewTaakAuditTrail'" />
<EditRol />
<ViewZaakAuditTrail v-if="navigationStore.modal === 'viewZaakAuditTrail'" />
<ViewKlantRegister v-if="navigationStore.modal === 'viewKlantRegister'" />
<DeleteContactMoment v-if="navigationStore.modal === 'deleteContactMoment'" />
<EditMedewerker v-if="navigationStore.modal === 'editMedewerker'" />
Expand All @@ -37,6 +40,8 @@ import ViewZaakAuditTrail from './zaken/ViewZaakAuditTrail.vue'
import ViewKlantRegister from './klantRegister/ViewKlantRegister.vue'
import DeleteContactMoment from './contactMomenten/DeleteContactMoment.vue'
import EditMedewerker from './medewerkers/EditMedewerker.vue'
import AddBerichtToZaak from './zaken/AddBerichtToZaak.vue'
export default {
name: 'Modals',
components: {
Expand All @@ -54,6 +59,7 @@ export default {
ViewKlantRegister,
DeleteContactMoment,
EditMedewerker,
AddBerichtToZaak,
},
}
</script>
145 changes: 145 additions & 0 deletions src/modals/zaken/AddBerichtToZaak.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<script setup>
import { zaakStore, navigationStore, berichtStore } from '../../store/store.js'
</script>

<template>
<NcModal ref="modalRef"
label-id="addBerichtToZaak"
@close="closeModal">
<div class="modalContent">
<h2>Bericht toevoegen aan {{ zaakStore.zaakItem.title }}</h2>

<div v-if="success !== null || error">
<NcNoteCard v-if="success" type="success">
<p>Bericht succesvol toegevoegd aan zaak</p>
</NcNoteCard>
<NcNoteCard v-if="error" type="error">
<p>{{ error }}</p>
</NcNoteCard>
</div>

<div v-if="success === null" class="form-group">
<NcSelect v-bind="berichten"
v-model="berichten.value"
input-label="Bericht"
:loading="berichtenLoading"
:disabled="loading"
required />
</div>

<NcButton v-if="success === null"
:disabled="!berichten?.value || loading"
type="primary"
@click="addBerichtToZaak">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<Plus v-if="!loading" :size="20" />
</template>
Toevoegen
</NcButton>
</div>
</NcModal>
</template>

<script>
import { NcButton, NcModal, NcLoadingIcon, NcNoteCard, NcSelect } from '@nextcloud/vue'
import { Zaak } from '../../entities/index.js'
import _ from 'lodash'
import Plus from 'vue-material-design-icons/Plus.vue'
export default {
name: 'AddBerichtToZaak',
components: {
NcModal,
NcButton,
NcLoadingIcon,
NcNoteCard,
NcSelect,
// Icons
Plus,
},
data() {
return {
berichtenLoading: false,
berichten: [],
loading: false,
success: null,
error: false,
errorCode: '',
hasUpdated: false,
}
},
mounted() {
this.fetchBerichtenData()
},
methods: {
closeModal() {
navigationStore.setModal(false)
},
fetchBerichtenData() {
this.berichtenLoading = true
berichtStore.refreshBerichtenList()
.then(({ data }) => {
this.berichten = {
options: data
.filter((bericht) => !zaakStore.zaakItem.berichten.includes(bericht.id))
.map((bericht) => ({
id: bericht.id,
label: bericht.title,
})),
}
})
.catch((err) => {
console.error(err)
})
.finally(() => {
this.berichtenLoading = false
})
},
addBerichtToZaak() {
this.loading = true
this.error = false
const zaakItemCopy = _.cloneDeep(zaakStore.zaakItem)
if (zaakItemCopy.berichten) {
zaakItemCopy.berichten.push(this.berichten.value.id)
} else {
zaakItemCopy.berichten = [this.berichten.value.id]
}
const newZaakItem = new Zaak(zaakItemCopy)
zaakStore.saveZaak(newZaakItem)
.then(({ response }) => {
this.success = response.ok
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.success = null
self.closeModal()
}, 2000)
this.hasUpdated = false
})
.catch((err) => {
this.error = err
this.hasUpdated = false
})
.finally(() => {
this.loading = false
})
},
},
}
</script>

<style scoped>
.modalContent {
margin: var(--zaa-margin-50, 12px);
text-align: center;
}
</style>
6 changes: 3 additions & 3 deletions src/store/modules/zaken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export const useZaakStore = defineStore('zaken', {
throw new Error('No zaak item to save')
}

const isNewZaak = !zaakItem.uuid
const isNewZaak = !zaakItem.id
const endpoint = isNewZaak
? `${apiEndpoint}`
: `${apiEndpoint}/${zaakItem.uuid}`
: `${apiEndpoint}/${zaakItem.id}`
const method = isNewZaak ? 'POST' : 'PUT'

console.info('Saving zaak item with id: ' + zaakItem.uuid)
console.info('Saving zaak item with id: ' + zaakItem.id)

const response = await fetch(
endpoint,
Expand Down
62 changes: 33 additions & 29 deletions src/views/berichten/ZaakBerichten.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup>
import { navigationStore, berichtStore } from '../../store/store.js'
import { navigationStore, berichtStore, zaakStore } from '../../store/store.js'
</script>

<template>
<div>
<div v-if="!loading">
<NcListItem v-for="(bericht, i) in berichtenList"
<div v-if="!loading && !!filteredBerichten?.length">
<NcListItem v-for="(bericht, i) in filteredBerichten"
:key="`${bericht}${i}`"
:name="bericht?.onderwerp"
:active="berichtStore.berichtItem?.id === bericht.id"
Expand All @@ -22,17 +22,29 @@ import { navigationStore, berichtStore } from '../../store/store.js'
{{ bericht?.berichttekst }}
</template>
<template #actions>
<NcActionButton @click="editBericht(bericht)">
Bewerken
<NcActionButton @click="berichtStore.setBerichtItem(bericht); navigationStore.setSelected('berichten')">
<template #icon>
<Eye :size="20" />
</template>
Bekijken
</NcActionButton>
<!-- <NcActionButton @click="berichtStore.setBerichtItem(bericht); navigationStore.setModal('editBericht')">
<template #icon>
<Pencil :size="20" />
</template>
Bewerken
</NcActionButton> -->
<NcActionButton>
Verwijderen
<template #icon>
<TrashCanOutline :size="20" />
</template>
Verwijderen van zaak
</NcActionButton>
</template>
</NcListItem>
</div>

<div v-if="!berichtenList?.length && !loading">
<div v-if="!filteredBerichten?.length && !loading">
Geen berichten gevonden.
</div>

Expand All @@ -49,6 +61,9 @@ import { NcListItem, NcActionButton, NcLoadingIcon } from '@nextcloud/vue'
// Icons
import ChatOutline from 'vue-material-design-icons/ChatOutline.vue'
import Eye from 'vue-material-design-icons/Eye.vue'
import Pencil from 'vue-material-design-icons/Pencil.vue'
import TrashCanOutline from 'vue-material-design-icons/TrashCanOutline.vue'
export default {
name: 'ZaakBerichten',
Expand All @@ -68,38 +83,27 @@ export default {
return {
search: '',
loading: true,
berichtenList: [],
}
},
computed: {
filteredBerichten() {
return berichtStore.berichtenList.filter(bericht => zaakStore.zaakItem.berichten.includes(bericht.id))
},
},
watch: {
zaakId(newVal) {
this.fetchData(newVal)
this.fetchData()
},
},
mounted() {
this.fetchData(this.zaakId)
this.fetchData()
},
methods: {
editBericht(bericht) {
berichtStore.setBerichtItem(bericht)
navigationStore.setModal('editBericht')
},
fetchData(zaakId) {
fetchData() {
this.loading = true
fetch(
'/index.php/apps/zaakafhandelapp/api/berichten',
{
method: 'GET',
},
)
.then((response) => {
response.json().then((data) => {
this.berichtenList = data.results || []
})
this.loading = false
})
.catch((err) => {
console.error(err)
berichtStore.refreshBerichtenList()
.finally(() => {
this.loading = false
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/views/eigenschappen/ZaakEigenschappen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default {
data() {
return {
search: '',
loading: true,
loading: false,
zakenList: [],
}
},
Expand Down
Loading

0 comments on commit 3e3f615

Please sign in to comment.