Skip to content

Commit 48918e3

Browse files
authored
Fix auth, mobile menu, other component warnings (#172)
* Fix auth, mobile menu, other component warnings * fix errors for page and menu load
1 parent 9ceeb63 commit 48918e3

File tree

14 files changed

+94
-99
lines changed

14 files changed

+94
-99
lines changed

curriculum-back/server/api/auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ router.route('/register')
7474
}
7575
res.status(201).send({ username, email })
7676
} else {
77-
res.send('Invalid credentials').status(400)
77+
res.status(400).send('Invalid credentials')
7878
}
7979
} catch(err) {
8080
console.error(err)

curriculum-back/server/api/curricula.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ router.route('/')
3232
authRouter.route('/')
3333
.post(async function (req, res) {
3434
const { name, goal, description, sections, createdBy } = req.body
35+
console.log("*" * 10)
36+
console.log(req.body)
3537
const curriculum = new Curriculum({
3638
name,
3739
goal,

curriculum-front/src/App.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<v-app :theme="theme">
3-
<TopNav :openDrawer="openDrawer" v-model:theme="theme" />
3+
<TopNav v-model:theme="theme" />
44
<MobileDrawer />
55

6-
<v-content>
6+
<v-main>
77
<RouterView />
8-
</v-content>
8+
</v-main>
99
<v-snackbar v-model="snackbarOptions.show" :multi-line="true" :right="true" :top="true" :timeout="6000"
1010
:color="snackbarOptions.variant">
1111
{{ snackbarOptions.message }}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<template>
22
<v-navigation-drawer v-if="mobile" v-model="isDrawerOpen" app right temporary>
33
<v-list dense>
4-
<v-list-item v-for="item in navItems" :key="item.name" link>
5-
<v-list-item-icon>
6-
<v-icon>mdi-{{ item.icon }}</v-icon>
7-
</v-list-item-icon>
4+
<v-list-item v-for="item in navItems" :key="item.name" :to="item.route" link>
5+
<template v-slot:prepend>
6+
<v-icon :icon="`mdi-${item.icon}`"></v-icon>
7+
</template>
88

9-
<v-list-item-content>
10-
<v-list-item-title>{{ item.title }}</v-list-item-title>
11-
</v-list-item-content>
9+
<v-list-item-title>{{ item.title }}</v-list-item-title>
1210
</v-list-item>
1311
</v-list>
1412
</v-navigation-drawer>
@@ -18,20 +16,57 @@
1816
import { ref, toRefs } from 'vue'
1917
import { useDisplay } from 'vuetify'
2018
19+
import { useAuthStore } from '@/stores/auth'
2120
import { useGeneralStore } from '@/stores/general'
2221
2322
const { mobile } = useDisplay()
23+
const authStore = useAuthStore()
2424
const generalStore = useGeneralStore()
2525
const { isDrawerOpen } = toRefs(generalStore)
2626
27-
const navItems = ref([
27+
const navItems_ = [
2828
{
29-
name: 'Home',
30-
icon: 'home'
29+
title: 'Home',
30+
icon: 'home',
31+
route: '/',
3132
},
32-
{
33-
name: 'View All',
34-
icon: 'magnify'
35-
}
36-
])
33+
]
34+
if (authStore.user.token) {
35+
navItems_.push(
36+
{
37+
title: 'View All',
38+
icon: 'view-list',
39+
route: '/curricula',
40+
},
41+
{
42+
title: 'Create',
43+
icon: 'plus',
44+
route: '/curricula/create',
45+
},
46+
{
47+
title: 'Settings',
48+
icon: 'cog',
49+
route: '/settings',
50+
},
51+
{
52+
title: 'Log Out',
53+
icon: 'logout',
54+
route: '/logout',
55+
},
56+
)
57+
} else {
58+
navItems_.push(
59+
{
60+
title: 'Log In',
61+
icon: 'login',
62+
route: '/login',
63+
},
64+
{
65+
title: 'Register',
66+
icon: 'account-plus',
67+
route: '/register',
68+
},
69+
)
70+
}
71+
const navItems = ref(navItems_)
3772
</script>

curriculum-front/src/components/TopNav.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@click="toggleTheme" variant="outlined" class="mr-4" />
1616

1717
<v-toolbar-items v-if="mobile">
18-
<v-btn @click="openDrawer()">
18+
<v-btn @click="generalStore.isDrawerOpen = true">
1919
Menu
2020
</v-btn>
2121
</v-toolbar-items>
@@ -56,26 +56,27 @@
5656
</template>
5757

5858
<script setup>
59-
import { ref, toRefs } from 'vue'
59+
import { toRefs } from 'vue'
6060
import { useDisplay } from 'vuetify'
6161
6262
import { useAuthStore } from '@/stores/auth'
63+
import { useGeneralStore } from '@/stores/general'
6364
6465
const { mobile } = useDisplay()
65-
const openDrawer = ref(null)
6666
6767
const logout = () => {
6868
authStore.logUserOut()
6969
}
7070
7171
const authStore = useAuthStore()
72+
const generalStore = useGeneralStore()
7273
const { user } = toRefs(authStore)
7374
7475
const props = defineProps({
7576
theme: {
7677
type: String,
7778
required: true,
78-
}
79+
},
7980
})
8081
8182
const emit = defineEmits(['update:theme'])

curriculum-front/src/components/create-form/MainForm.vue

+8-26
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<v-subheader>Name *</v-subheader>
1212
</v-col>
1313
<v-col cols="9">
14-
<v-text-field v-model="state.selectedCurriculum.name" :error-messages="nameErrors" />
14+
<v-text-field v-model="state.selectedCurriculum.name" />
1515
</v-col>
1616
</v-row>
1717
<v-row>
@@ -42,38 +42,20 @@
4242
</template>
4343

4444
<script setup>
45-
import { computed, toRefs } from 'vue'
45+
import { toRefs } from 'vue'
46+
4647
import FormSections from './FormSections.vue'
48+
import { useAuthStore } from '@/stores/auth'
4749
import { useCurriculumStore } from '@/stores/curricula'
4850
4951
const curriculumStore = useCurriculumStore()
52+
const authStore = useAuthStore()
53+
const { user } = toRefs(authStore)
5054
5155
const { state } = toRefs(curriculumStore)
5256
53-
const nameErrors = computed(() => {
54-
const errors = []
55-
if (!state.value.selectedCurriculum.value.name.$dirty) return errors
56-
!state.value.selectedCurriculum.value.name.maxLength && errors.push('Name must be at most 20 characters long.')
57-
!state.value.selectedCurriculum.value.name.required && errors.push('Name is required.')
58-
return errors
59-
})
60-
61-
// const sectionNameErrors = (i) => {
62-
// const errors = []
63-
// if (!sections.value[i].name.$dirty) return errors
64-
// !sections.value[i].name.maxLength && errors.push('Name must be at most 30 characters long.')
65-
// !sections.value[i].name.required && errors.push('Name is required.')
66-
// return errors
67-
// }
68-
69-
// const sectionUrlErrors = (i, type) => {
70-
// const errors = []
71-
// if (!sections.value[i][`new${type}`].url.$model.length) return errors
72-
// !sections.value[i][`new${type}`].url.url && errors.push('Must be a valid url.')
73-
// return errors
74-
// }
75-
7657
const submit = () => {
77-
curriculumStore.patchCurriculum()
58+
state.value.selectedCurriculum.createdBy = user.value.id
59+
curriculumStore.postCurriculum()
7860
}
7961
</script>

curriculum-front/src/components/display-curriculum/Header.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const props = defineProps({
8282
const emit = defineEmits(['selectCurriculum:update'])
8383
8484
const curriculum_ = computed({
85-
get: () => props.selectCurriculum,
85+
get: () => props.selectedCurriculum,
8686
set: () => {
8787
emit('selectCurriculum:update', props.selectedCurriculum)
8888
}

curriculum-front/src/router/routes.js

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import ResetPassword from '@/views/auth/ResetPassword.vue'
99
import Verify from '@/views/auth/Verify.vue'
1010
import Settings from '@/views/Settings.vue'
1111

12+
import { useAuthStore } from '@/stores/auth'
13+
1214
export default [
1315
{
1416
path: '/',
@@ -40,6 +42,15 @@ export default [
4042
name: 'verify',
4143
component: Verify
4244
},
45+
{
46+
path: '/logout',
47+
name: 'logout',
48+
beforeEnter: (to, from, next) => {
49+
const authStore = useAuthStore()
50+
authStore.logUserOut()
51+
next('/login')
52+
},
53+
},
4354
{
4455
path: '/settings',
4556
name: 'settings',

curriculum-front/src/stores/auth.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ export const useAuthStore = defineStore('auth', () => {
5757
}
5858

5959
async function logUserOut() {
60-
clearUserInfo()
6160
localStorage.removeItem('token')
62-
router.replace('/')
61+
clearUserInfo()
6362
}
6463

6564
function updateUser(payload) {

curriculum-front/src/stores/curricula/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ export const useCurriculumStore = defineStore('curriculum', () => {
3939
}
4040
}
4141

42-
const postCurriculum = async (curriculum) => {
42+
const postCurriculum = async () => {
43+
const curriculum = state.value.selectedCurriculum
4344
const res = await axios.post('curricula', curriculum)
4445
state.value.curricula.push(res.data)
4546
router.push(`/curricula/${res.data._id}`)
4647
}
4748

4849
const patchCurriculum = async () => {
4950
const { _id: curriculumId } = state.value.selectedCurriculum
50-
await axios.patch(`curricula/${curriculumId}`, state.value.selectedCurriculum)
51+
const res = await axios.patch(`curricula/${curriculumId}`, state.value.selectedCurriculum)
52+
state.value.selectedCurriculum = res.data
5153
}
5254

5355
const deleteCurriculum = async (curriculumId) => {

curriculum-front/src/stores/general.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const useGeneralStore = defineStore('generalStore', () => {
88
message: '',
99
})
1010
const isLoading = ref(false)
11+
const isDrawerOpen = ref(false)
1112

1213
const updateSnackbar = (settings) => {
1314
snackbarOptions.value = {
@@ -19,6 +20,7 @@ export const useGeneralStore = defineStore('generalStore', () => {
1920
return {
2021
snackbarOptions,
2122
isLoading,
23+
isDrawerOpen,
2224
updateSnackbar,
2325
}
2426
})

curriculum-front/src/views/CreateCurriculum.vue

-34
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,5 @@
77
</template>
88

99
<script setup>
10-
import { toRefs } from 'vue'
11-
1210
import MainForm from '@/components/create-form/MainForm.vue'
13-
14-
import { useAuthStore } from '@/stores/auth'
15-
import { useCurriculumStore } from '@/stores/curricula'
16-
17-
const authStore = useAuthStore()
18-
const { user } = toRefs(authStore)
19-
const { postCurriculum } = useCurriculumStore()
20-
21-
const saveCurriculum = (curriculumInfo, sections) => {
22-
const newSections = sections.map((section) => {
23-
let updatedSection = { ...section }
24-
delete updatedSection.newResource
25-
delete updatedSection.newProject
26-
return updatedSection
27-
})
28-
29-
const curriculum = {
30-
...curriculumInfo,
31-
sections: newSections,
32-
createdBy: user.value.id
33-
}
34-
35-
postCurriculum(curriculum)
36-
}
37-
38-
// computed: {
39-
// ...mapState('auth', ['user'])
40-
// },
41-
// methods: {
42-
// ...mapActions(['postCurriculum']),
43-
// ...mapMutations(['updateSnackbar']),
44-
// }
4511
</script>

curriculum-front/src/views/DisplayCurriculum.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const generalStore = useGeneralStore()
4444
const route = useRoute()
4545
4646
const { user } = toRefs(authStore)
47-
const { selectedCurriculum } = toRefs(curriculumStore)
47+
const { selectedCurriculum } = toRefs(curriculumStore.state)
4848
4949
const tempSection = ref({
5050
name: '',

curriculum-front/src/views/auth/Verify.vue

+5-10
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
Verify E-mail
55
</template>
66
<template #form>
7-
<v-text-field
8-
label="E-mail"
9-
v-model="email"
10-
/>
11-
<v-text-field
12-
label="Code"
13-
v-model="code"
14-
/>
7+
<v-text-field label="Email" v-model="email" :error-messages="emailErrors" required variant="outlined" />
8+
<v-text-field label="Code" v-model="code" :error-messages="emailErrors" required variant="outlined" />
159
</template>
1610
<template #actions>
17-
<v-btn @click="submit" color="primary">Verify</v-btn>
11+
<v-btn @click="submit" color="primary" variant="outlined">Verify</v-btn>
1812
</template>
1913
<template #link>
20-
<p class="pa-2">Don't have an account? <router-link :to="{name: 'register'}">Register here</router-link></p>
14+
<p class="mb-1 mt-4">Don't have an account? <router-link :to="{ name: 'register' }">Register here</router-link>
15+
</p>
2116
</template>
2217
</AuthTemplate>
2318
</template>

0 commit comments

Comments
 (0)