Skip to content

Commit 0527401

Browse files
authored
Add dialog for updating wiki profiles (#977)
1 parent aacdd27 commit 0527401

File tree

6 files changed

+127
-7
lines changed

6 files changed

+127
-7
lines changed

src/backend/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const updateLogo = async ({ file, fileName, wikiId }) => {
7777
export const updateSetting = async (setting, payload) => axios.post(`/wiki/setting/${setting}/update`, { ...payload, setting })
7878
export const updateSkin = async payload => updateSetting('wgDefaultSkin', payload)
7979
export const wikiDetails = async payload => (await axios.post('/wiki/details', payload)).data.data
80+
export const updateProfile = async payload => axios.post('/wiki/profile', payload)
8081
export const wikiDiscovery = async ({ sort, direction, active, currentPage, resultsPerPage }) => {
8182
return (await axios.get('/wiki', {
8283
params: {

src/components/Cards/CreateWiki.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
v-show="step === 2"
1717
:title="title"
1818
:inFlight="inFlight"
19+
:dismissable="false"
1920
v-model="stepTwo"
2021
@previous-step="goToStep(1)"
2122
@next-step="goToStep(3)"
@@ -26,6 +27,9 @@
2627
:title="title"
2728
:inFlight="inFlight"
2829
:error="error"
30+
:dismissable="false"
31+
:showTerms="true"
32+
submitButtonText="Create Wiki"
2933
v-model="stepThree"
3034
@previous-step="goToStep(2)"
3135
@submit="createWiki"

src/components/Cards/CreateWikiWizardStepThree.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<v-card class="elevation-12">
33
<v-toolbar dark color="primary">
44
<v-toolbar-title>{{ title }}</v-toolbar-title>
5+
<v-spacer></v-spacer>
6+
<v-btn v-if="dismissable" icon @click="$emit('close-dialog')">
7+
<v-icon>mdi-close</v-icon>
8+
</v-btn>
59
</v-toolbar>
610

711
<v-card-text>
@@ -51,11 +55,12 @@
5155
</v-radio>
5256
</v-radio-group>
5357

54-
<h3 class="mt-6">Terms of Use</h3>
58+
<h3 v-if="showTerms" class="mt-6">Terms of Use</h3>
5559
<v-checkbox
5660
v-model="value.terms"
5761
:disabled="inFlight"
5862
:rules="[() => !!value.terms || 'You must accept the Terms of Service.']"
63+
v-if="showTerms"
5964
>
6065
<template v-slot:label>
6166
<div>
@@ -94,7 +99,7 @@
9499
:disabled="inFlight"
95100
@click="submitWholeForm"
96101
>
97-
Create Wiki
102+
{{ submitButtonText }}
98103
</v-btn>
99104
</v-card-actions>
100105
</v-card>
@@ -107,7 +112,10 @@ export default {
107112
title: String,
108113
inFlight: Boolean,
109114
value: Object,
110-
error: Array
115+
error: Array,
116+
dismissable: Boolean,
117+
showTerms: Boolean,
118+
submitButtonText: String
111119
},
112120
methods: {
113121
previousStep () {

src/components/Cards/CreateWikiWizardStepTwo.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<v-card class="elevation-12">
33
<v-toolbar dark color="primary">
44
<v-toolbar-title>{{ title }}</v-toolbar-title>
5+
<v-spacer></v-spacer>
6+
<v-btn v-if="dismissable" icon @click="$emit('close-dialog')">
7+
<v-icon>mdi-close</v-icon>
8+
</v-btn>
59
</v-toolbar>
610

711
<v-card-text>
@@ -100,7 +104,7 @@
100104

101105
<v-card-actions>
102106
<v-spacer></v-spacer>
103-
<v-btn type="button" :disabled="inFlight" @click="$emit('previous-step')">
107+
<v-btn v-if="$listeners['previous-step']" type="button" :disabled="inFlight" @click="$emit('previous-step')">
104108
&lt; PREVIOUS
105109
</v-btn>
106110
<v-btn type="button" color="primary" :disabled="inFlight" @click="nextStep">
@@ -116,7 +120,8 @@ export default {
116120
props: {
117121
title: String,
118122
inFlight: Boolean,
119-
value: Object
123+
value: Object,
124+
dismissable: Boolean
120125
},
121126
data () {
122127
return {

src/components/Pages/ManageWiki/Cards/Profile.vue

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
<template>
22
<v-form ref="form">
3+
<v-overlay :value="dialog.show">
4+
<v-dialog
5+
content-class="update-wiki-profile-dialog"
6+
v-model="dialog.show"
7+
>
8+
<step-two-card
9+
v-show="dialog.step === 1"
10+
:title="dialog.title"
11+
:inFlight="inFlight"
12+
:dismissable="true"
13+
v-model="dialog.data.stepOne"
14+
@close-dialog="dialog.show = false"
15+
@next-step="goToStep(2)"
16+
/>
17+
<step-three-card
18+
v-show="dialog.step === 2"
19+
:title="dialog.title"
20+
:inFlight="inFlight"
21+
:error="dialog.error"
22+
:dismissable="true"
23+
:showTerms="false"
24+
submitButtonText="Set intended use"
25+
v-model="dialog.data.stepTwo"
26+
@close-dialog="dialog.show = false"
27+
@previous-step="goToStep(1)"
28+
@submit="updateProfile"
29+
/>
30+
</v-dialog>
31+
</v-overlay>
332
<v-card>
433
<v-card-title class="card-title">
534
<span>Intended use</span>
@@ -40,12 +69,17 @@
4069
<span v-if="updatedAt" class="updated-at">{{ updatedAt }}</span>
4170
</v-card-text>
4271
<Message ref="message" />
72+
<v-card-actions>
73+
<v-btn :disabled="inFlight" @click="showDialog()">Set intended use</v-btn>
74+
</v-card-actions>
4375
</v-card>
4476
</v-form>
4577
</template>
4678

4779
<script>
4880
import Message from '../Features/Message.vue'
81+
import StepTwoCard from '~/components/Cards/CreateWikiWizardStepTwo'
82+
import StepThreeCard from '~/components/Cards/CreateWikiWizardStepThree'
4983
5084
const providedResponses = {
5185
purpose: {
@@ -69,14 +103,36 @@ const providedResponses = {
69103
export default {
70104
name: 'Profile',
71105
components: {
72-
Message
106+
Message,
107+
StepTwoCard,
108+
StepThreeCard
73109
},
74110
props: [
75111
'wikiId'
76112
],
77113
data () {
78114
return {
79-
profile: {}
115+
inFlight: false,
116+
profile: {},
117+
dialog: {
118+
show: false,
119+
title: 'Set intended use',
120+
error: [],
121+
step: 1,
122+
data: {},
123+
dataTemplate: {
124+
stepOne: {
125+
purpose: '',
126+
otherPurpose: '',
127+
audience: '',
128+
otherAudience: ''
129+
},
130+
stepTwo: {
131+
temporality: '',
132+
otherTemporality: ''
133+
}
134+
}
135+
}
80136
}
81137
},
82138
computed: {
@@ -107,6 +163,40 @@ export default {
107163
return providedResponses[question][providedResponse]
108164
}
109165
return 'No answer selected.'
166+
},
167+
showDialog () {
168+
this.dialog.step = 1
169+
this.dialog.data = JSON.parse(JSON.stringify(this.dialog.dataTemplate))
170+
this.dialog.show = true
171+
},
172+
goToStep (stepNumber) {
173+
this.dialog.step = stepNumber
174+
},
175+
async updateProfile () {
176+
this.inFlight = true
177+
178+
try {
179+
const profile = {
180+
purpose: this.dialog.data.stepOne.purpose,
181+
...(this.dialog.data.stepOne.otherPurpose && { purpose_other: this.dialog.data.stepOne.otherPurpose }),
182+
...(this.dialog.data.stepOne.audience && { audience: this.dialog.data.stepOne.audience }),
183+
...(this.dialog.data.stepOne.otherAudience && { audience_other: this.dialog.data.stepOne.otherAudience }),
184+
temporality: this.dialog.data.stepTwo.temporality,
185+
...(this.dialog.data.stepTwo.otherTemporality && { temporality_other: this.dialog.data.stepTwo.otherTemporality })
186+
}
187+
188+
this.profile = (await this.$store.dispatch('updateProfile', {
189+
wiki: this.wikiId, profile: JSON.stringify(profile)
190+
})).data.data ?? {}
191+
192+
this.$refs.message.show('success', 'Intended use has been updated.')
193+
this.dialog.show = false
194+
} catch (error) {
195+
console.log(error)
196+
this.$refs.message.show('error', 'Something went wrong with updating your intended use. Please try again.')
197+
} finally {
198+
this.inFlight = false
199+
}
110200
}
111201
},
112202
async created () {
@@ -121,6 +211,15 @@ export default {
121211
}
122212
</script>
123213
214+
<style lang="css">
215+
.update-wiki-profile-dialog {
216+
max-width: 356px;
217+
}
218+
.update-wiki-profile-dialog.v-dialog > .v-card > .v-card__text {
219+
padding: 16px;
220+
}
221+
</style>
222+
124223
<style lang="css" scoped>
125224
.card-title {
126225
display: flex;

src/store/wikis.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ const actions = {
197197
updateSetting ({ commit }, payload) {
198198
return api.updateSetting(payload.setting, payload)
199199
},
200+
updateProfile ({ commit }, payload) {
201+
return api.updateProfile(payload)
202+
},
200203
triggerEntityImport ({ commit }, wikiId) {
201204
return api.importEntities({ wikiId })
202205
.then(() => {

0 commit comments

Comments
 (0)