1
- <script >
2
- import { mapActions , mapState } from ' pinia' ;
1
+ <script setup >
2
+ import { storeToRefs } from ' pinia' ;
3
3
import { useI18n } from ' vue-i18n' ;
4
+ import { useRouter } from ' vue-router' ;
5
+ import { computed , inject , onMounted , ref } from ' vue' ;
4
6
5
7
import AuditHistory from ' ~/components/forms/submission/AuditHistory.vue' ;
6
8
import DeleteSubmission from ' ~/components/forms/submission/DeleteSubmission.vue' ;
@@ -13,87 +15,77 @@ import { checkSubmissionUpdate } from '~/utils/permissionUtils';
13
15
import { useFormStore } from ' ~/store/form' ;
14
16
import { NotificationTypes } from ' ~/utils/constants' ;
15
17
16
- export default {
17
- components: {
18
- AuditHistory,
19
- DeleteSubmission,
20
- FormViewer,
21
- NotesPanel,
22
- StatusPanel,
23
- PrintOptions,
24
- },
25
- inject: [' setWideLayout' ],
26
- props: {
27
- submissionId: {
28
- type: String ,
29
- required: true ,
30
- },
31
- },
32
- setup () {
33
- const { locale } = useI18n ({ useScope: ' global' });
18
+ const { locale } = useI18n ({ useScope: ' global' });
19
+ const router = useRouter ();
34
20
35
- return { locale };
36
- },
37
- data () {
38
- return {
39
- isDraft: true ,
40
- loading: true ,
41
- reRenderSubmission: 0 ,
42
- submissionReadOnly: true ,
43
- isWideLayout: false ,
44
- };
45
- },
46
- computed: {
47
- ... mapState (useFormStore, [
48
- ' form' ,
49
- ' formSubmission' ,
50
- ' permissions' ,
51
- ' isRTL' ,
52
- ]),
53
- NOTIFICATIONS_TYPES () {
54
- return NotificationTypes;
55
- },
56
- },
57
- async mounted () {
58
- await this .fetchSubmission ({ submissionId: this .submissionId });
59
- // get current user's permissions on associated form
60
- await this .getFormPermissionsForUser (this .form .id );
61
- this .loading = false ;
62
- // set wide layout
63
- this .setWideLayout (this .isWideLayout );
21
+ const setWideLayout = inject (' setWideLayout' );
22
+
23
+ const properties = defineProps ({
24
+ submissionId: {
25
+ type: String ,
26
+ required: true ,
64
27
},
65
- methods: {
66
- ... mapActions (useFormStore, [
67
- ' fetchSubmission' ,
68
- ' getFormPermissionsForUser' ,
69
- ]),
70
- checkSubmissionUpdate: checkSubmissionUpdate,
71
- onDelete () {
72
- this .$router .push ({
73
- name: ' FormSubmissions' ,
74
- query: {
75
- f: this .form .id ,
76
- },
77
- });
78
- },
79
- refreshNotes () {
80
- this .$refs .notesPanel .getNotes ();
81
- },
28
+ });
82
29
83
- setDraft (status ) {
84
- this .isDraft = status === ' REVISING' ;
85
- },
86
- async toggleWideLayout () {
87
- this .isWideLayout = ! this .isWideLayout ;
88
- this .setWideLayout (this .isWideLayout );
89
- },
90
- async toggleSubmissionEdit (editing ) {
91
- this .submissionReadOnly = ! editing;
92
- this .reRenderSubmission += 1 ;
93
- await this .fetchSubmission ({ submissionId: this .submissionId });
30
+ const isDraft = ref (true );
31
+ const loading = ref (true );
32
+ const notesPanel = ref (null );
33
+ const reRenderSubmission = ref (0 );
34
+ const submissionReadOnly = ref (true );
35
+ const isWideLayout = ref (false );
36
+
37
+ const formStore = useFormStore ();
38
+
39
+ const { form , formSubmission , permissions , isRTL } = storeToRefs (formStore);
40
+
41
+ const NOTIFICATIONS_TYPES = computed (() => NotificationTypes);
42
+
43
+ onMounted (async () => {
44
+ await formStore .fetchSubmission ({ submissionId: properties .submissionId });
45
+ // get current user's permissions on associated form
46
+ await formStore .getFormPermissionsForUser (form .value .id );
47
+ loading .value = false ;
48
+ // set wide layout
49
+ setWideLayout (isWideLayout .value );
50
+ });
51
+
52
+ function onDelete () {
53
+ router .push ({
54
+ name: ' FormSubmissions' ,
55
+ query: {
56
+ f: form .value .id ,
94
57
},
95
- },
96
- };
58
+ });
59
+ }
60
+
61
+ // TODO: This should be updated to an emit so we can test it
62
+ function refreshNotes () {
63
+ notesPanel .value .getNotes ();
64
+ }
65
+
66
+ function setDraft (status ) {
67
+ isDraft .value = status === ' REVISING' ;
68
+ }
69
+
70
+ function toggleWideLayout () {
71
+ isWideLayout .value = ! isWideLayout .value ;
72
+ setWideLayout (isWideLayout .value );
73
+ }
74
+
75
+ async function toggleSubmissionEdit (editing ) {
76
+ submissionReadOnly .value = ! editing;
77
+ reRenderSubmission .value += 1 ;
78
+ await formStore .fetchSubmission ({ submissionId: properties .submissionId });
79
+ }
80
+
81
+ defineExpose ({
82
+ isDraft,
83
+ onDelete,
84
+ refreshNotes,
85
+ setDraft,
86
+ submissionReadOnly,
87
+ toggleSubmissionEdit,
88
+ });
97
89
</script >
98
90
99
91
<template >
0 commit comments