Skip to content

Commit 2b4670f

Browse files
authored
Add message popup to experinece and education (#193)
1 parent e95fdfb commit 2b4670f

File tree

5 files changed

+162
-51
lines changed

5 files changed

+162
-51
lines changed

components/Message.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div
33
v-if="state.shown"
44
class="flex flex-col justify-start border p-4"
5-
:class="props.type">
5+
:class="props.type"
6+
>
67
<div class="flex flex-row justify-between items-center mb-2">
78
<img
89
class="msg-icon w-5 h-5 bg-contain"
@@ -11,41 +12,42 @@
1112
<i
1213
v-if="props.showCloseBtn"
1314
class="close-icon w-5 h-5 bg-contain"
14-
@click="state.shown = false">
15+
@click="state.shown = false"
16+
>
1517
</i>
1618
</div>
1719
<p class="msg-title font-bold">{{ props.title }}</p>
18-
<p class="msg-body"> <slot/> </p>
20+
<p class="msg-body"><slot /></p>
1921
</div>
2022
</template>
2123
<script setup>
2224
const props = defineProps({
2325
type: { type: String, default: 'info' },
2426
title: { type: String, default: '' },
25-
showCloseBtn: {type: Boolean, default: true}
27+
showCloseBtn: { type: Boolean, default: true },
2628
})
2729
const state = reactive({
28-
shown: true
30+
shown: true,
2931
})
3032
</script>
3133
<style scoped>
3234
.success {
3335
background-color: rgba(109, 185, 129, 0.1);
34-
border-color: #6DB981;
35-
color: #6DB981;
36+
border-color: #6db981;
37+
color: #6db981;
3638
}
3739
.error {
3840
background-color: rgba(242, 111, 84, 0.1);
39-
border-color: #F26F54;
40-
color: #F26F54;
41+
border-color: #f26f54;
42+
color: #f26f54;
4143
}
4244
.info {
4345
background-color: rgba(11, 150, 171, 0.1);
44-
border-color: #0B96AB;
45-
color: #0B96AB;
46+
border-color: #0b96ab;
47+
color: #0b96ab;
4648
}
4749
.close-icon {
48-
background-image: url('/assets/icons/message/close.svg');
50+
@apply bg-xIcon;
4951
}
5052
.close-icon:hover {
5153
cursor: pointer;

components/member/Banner.vue

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
<template>
22
<div id="banner" class="details-container">
3+
<Message
4+
v-if="state.error && !state.loading"
5+
title="Error"
6+
type="error"
7+
class="mb-4"
8+
>
9+
Something went wrong!
10+
</Message>
11+
<Message
12+
v-if="state.success && !state.loading"
13+
title="Saved"
14+
type="success"
15+
class="mb-4"
16+
>
17+
Settings saved successfully.
18+
</Message>
319
<div class="relative">
420
<div class="relative">
521
<img
@@ -142,13 +158,16 @@ const state = reactive({
142158
images: {
143159
cover: {
144160
url: props.member.cover_url,
145-
uploading: false
161+
uploading: false,
146162
},
147163
avatar: {
148164
url: props.member.avatar_url,
149-
uploading: false
165+
uploading: false,
150166
},
151-
}
167+
},
168+
loading: false,
169+
success: false,
170+
error: false,
152171
})
153172
154173
// placeholder images for when there are no images
@@ -160,6 +179,8 @@ const placeHolderImages = {
160179
161180
// handle uploading of the cover/avatar photo request
162181
const uploadImage = async (event, imageType) => {
182+
state.error = false
183+
state.loading = true
163184
state.images[imageType].uploading = true
164185
const { files } = await event.target
165186
const image = new FormData()
@@ -181,11 +202,20 @@ const uploadImage = async (event, imageType) => {
181202
// the 'last-updated' query is to prevent the browser from
182203
// using the cached image whenever a new one is available.
183204
// This is because the name of the images is based on the userId.
184-
state.images.cover.url = cover_url ? cover_url + '?last-updated=' + Date.now() : props.member.cover_url
185-
state.images.avatar.url = avatar_url ? avatar_url + '?last-updated=' + Date.now() : props.member.avatar_url
205+
state.images.cover.url = cover_url
206+
? cover_url + '?last-updated=' + Date.now()
207+
: props.member.cover_url
208+
state.images.avatar.url = avatar_url
209+
? avatar_url + '?last-updated=' + Date.now()
210+
: props.member.avatar_url
186211
useMember().value[`${imageType}_url`] = state.images[imageType].url
187212
}
188213
})
214+
.catch((error) => {
215+
state.loading = false
216+
state.error = true
217+
state.success = false
218+
})
189219
.finally(() => {
190220
updateGeneralInfo()
191221
})
@@ -205,14 +235,16 @@ const updateGeneralInfo = async (event) => {
205235
method: 'PATCH',
206236
body: JSON.stringify(bodyData),
207237
onResponse({ response }) {
238+
state.loading = false
208239
if (response._data) {
209-
console.log(response._data)
210-
console.log('updated!')
240+
state.error = false
241+
state.success = true
211242
}
212243
emit('updateMember')
213244
},
214245
onResponseError({ response }) {
215-
// TODO: handle errors on client side
246+
state.error = true
247+
state.success = false
216248
console.log('something went wrong', response._data.message)
217249
},
218250
})
@@ -305,15 +337,15 @@ img {
305337
max-height: 364px;
306338
}
307339
.cover:before {
308-
@apply w-full;
309-
@apply rounded-b-none rounded-lg;
310-
height: 20vw;
311-
max-height: 364px;
312-
content: ' ';
313-
display: block;
314-
background-image: url(/images/placeholders/729x164.png);
315-
background-size: contain;
316-
text-indent: -9999px;
340+
@apply w-full;
341+
@apply rounded-b-none rounded-lg;
342+
height: 20vw;
343+
max-height: 364px;
344+
content: ' ';
345+
display: block;
346+
background-image: url(/images/placeholders/729x164.png);
347+
background-size: contain;
348+
text-indent: -9999px;
317349
}
318350
319351
.general-info {

components/member/Details.vue

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
<template>
22
<div id="member-detail" class="details-container">
3+
<Message
4+
v-if="state.error && !state.loading"
5+
title="Error"
6+
type="error"
7+
class="mb-4"
8+
>
9+
Something went wrong!
10+
</Message>
11+
<Message
12+
v-if="state.success && !state.loading"
13+
title="Saved"
14+
type="success"
15+
class="mb-4"
16+
>
17+
Settings saved successfully.
18+
</Message>
319
<div class="flex justify-between w-full">
420
<h3 class="heading">About</h3>
521
<div v-if="memberAuth" class="flex gap-x-4 items-center">
@@ -73,6 +89,9 @@ const state = reactive({
7389
memberAbout: props.member.about,
7490
},
7591
settings: props.settings,
92+
loading: false,
93+
success: false,
94+
error: false,
7695
})
7796
7897
const formatDate = (date) => {
@@ -86,6 +105,10 @@ const formatDate = (date) => {
86105
87106
// handle updating the users general info
88107
const updateMemberDetailsInfo = async (event) => {
108+
state.loading = true
109+
state.error = false
110+
state.success = false
111+
89112
const bodyData = {
90113
about: state.form.memberAbout,
91114
}
@@ -94,14 +117,19 @@ const updateMemberDetailsInfo = async (event) => {
94117
method: 'PATCH',
95118
body: JSON.stringify(bodyData),
96119
onResponse({ response }) {
97-
if (response._data.success) {
120+
state.loading = false
121+
if (response.ok) {
98122
console.log(response._data)
99-
console.log('updated!')
123+
state.success = true
124+
state.error = false
125+
126+
console.log(state.success)
100127
}
101128
emit('updateMember')
102129
},
103130
onResponseError({ response }) {
104-
// TODO: handle errors on client side
131+
state.error = true
132+
state.success = false
105133
console.log('something went wrong', response._data.message)
106134
},
107135
})

0 commit comments

Comments
 (0)