Skip to content

Commit

Permalink
integrate user API
Browse files Browse the repository at this point in the history
  • Loading branch information
khanzadimahdi committed Apr 29, 2024
1 parent 154c614 commit 9e52ea4
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 184 deletions.
2 changes: 1 addition & 1 deletion frontend/components/dashboard/sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</li>
<li class="border-top my-3"></li>
<li class="my-2">
<NuxtLink to="/dashboard" class="btn align-items-center rounded collapsed">
<NuxtLink to="/dashboard/profile" class="btn align-items-center rounded collapsed">
<span class="bi ms-2 fa fa-user"></span>
<span>پروفایل</span>
</NuxtLink>
Expand Down
137 changes: 0 additions & 137 deletions frontend/components/editor.vue

This file was deleted.

10 changes: 10 additions & 0 deletions frontend/components/rich-editor.client.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<ckeditor :editor="ClassicEditor" />
</template>

<script setup>
import CKEditor from '@ckeditor/ckeditor5-vue';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
const ckeditor = CKEditor.component
</script>
43 changes: 37 additions & 6 deletions frontend/composables/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,47 @@ function userFetch<T> (url: string, options: UseFetchOptions<T> = {}) {
return $fetch(url, defu(options, defaults))
}

function profile() {

async function profile() {
return useUser().$fetch(
useApiUrlResolver().resolve("api/dashboard/profile"),
{
method: "GET",
lazy: true,
headers: {authorization: `Bearer ${useAuth().accessToken()}`}
}
)
}

function updateProfile() {

async function updateProfile(email:string, name?:string, username?:string, avatar?:string) {
return useUser().$fetch(
useApiUrlResolver().resolve("api/dashboard/profile"),
{
method: "PUT",
lazy: true,
headers: {authorization: `Bearer ${useAuth().accessToken()}`},
body: {
email: email,
name: name,
username: username,
avatar: avatar,
}
}
)
}

function updatePassword() {

async function updatePassword(currentPassword:string, newPassword:string) {
return useUser().$fetch(
useApiUrlResolver().resolve("api/dashboard/password"),
{
method: "PUT",
lazy: true,
headers: {authorization: `Bearer ${useAuth().accessToken()}`},
body: {
current_password: currentPassword,
new_password: newPassword,
}
}
)
}

export function useUser() {
Expand Down
5 changes: 1 addition & 4 deletions frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
build: {

},
vite: {
build: {
cssCodeSplit: false,
Expand All @@ -24,7 +21,7 @@ export default defineNuxtConfig({
}
}
},
modules: ['@vueuse/nuxt', "nuxt-tiptap-editor"],
modules: ['@vueuse/nuxt'],
runtimeConfig: {
internalApiBaseUrl: '',
public: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/dashboard/articles/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
</div>

<div class="form-floating mb-3">
<textarea :class="{ 'is-invalid': errors.body }" id="body" class="form-control" placeholder="متن اصلی مقاله" v-model="params.body" required></textarea>
<label for="body">متن اصلی مقاله</label>
<rich-editor :class="{ 'is-invalid': errors.body }" v-model="params.body" id="body" class="form-control" placeholder="متن اصلی مقاله" />
<div v-if="errors.body" class="invalid-feedback">
{{ errors.body }}
</div>
Expand Down
5 changes: 2 additions & 3 deletions frontend/pages/dashboard/articles/edit/[uuid].vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
</div>
</div>

<div class="form-floating mb-3">
<textarea :class="{ 'is-invalid': errors.body }" id="body" class="form-control" placeholder="متن اصلی مقاله" v-model="params.body" required></textarea>
<label for="body">متن اصلی مقاله</label>
<div class="mb-3">
<rich-editor :class="{ 'is-invalid': errors.body }" v-model="params.body" id="body" class="form-control" placeholder="متن اصلی مقاله" />
<div v-if="errors.body" class="invalid-feedback">
{{ errors.body }}
</div>
Expand Down
40 changes: 22 additions & 18 deletions frontend/pages/dashboard/articles/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<div class="row">
<div class="col-12 mb-4 mb-lg-0">
<div class="card">
<div class="card-header d-flex justify-content-between">
<h4>مقاله ها</h4>
<NuxtLink class="btn btn-primary" to="/dashboard/articles/create">مقاله جدید</NuxtLink>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover align-middle">
Expand All @@ -29,28 +33,28 @@
</thead>
<tbody v-if="!pending">
<tr v-for="(article, index) in data.items" :key="index">
<th scope="row">{{ index + 1 }}</th>
<td>{{ article.title }}</td>
<td>{{ article.published_at }}</td>
<td>
<NuxtLink :to="`/articles/${article.uuid}`" class="btn mx-1 btn-sm btn-primary">
<span class="fa fa-eye"></span>
</NuxtLink>
<NuxtLink :to="`/dashboard/articles/edit/${article.uuid}`" class="btn mx-1 btn-sm btn-primary">
<span class="fa fa-pen"></span>
</NuxtLink>
<button @click.prevent="deleteArticle(article.uuid)" type="button" class="btn mx-1 btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
</td>
<th scope="row">{{ index + 1 }}</th>
<td>{{ article.title }}</td>
<td>{{ article.published_at }}</td>
<td>
<NuxtLink :to="`/articles/${article.uuid}`" class="btn mx-1 btn-sm btn-primary">
<span class="fa fa-eye"></span>
</NuxtLink>
<NuxtLink :to="`/dashboard/articles/edit/${article.uuid}`" class="btn mx-1 btn-sm btn-primary">
<span class="fa fa-pen"></span>
</NuxtLink>
<button @click.prevent="deleteArticle(article.uuid)" type="button" class="btn mx-1 btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
</td>
</tr>
<tr v-if="data.items.length == 0">
<td colspan="5">
<p>هیچ مقاله ای وجود ندارد</p>
</td>
<td colspan="5">
<p>هیچ مقاله ای وجود ندارد</p>
</td>
</tr>
</tbody>
</table>
</table>
</div>
<nav v-if="!pending && data.pagination.total_pages > 1" aria-label="Page navigation example">
<ul class="pagination">
Expand Down
4 changes: 0 additions & 4 deletions frontend/pages/dashboard/files/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ useHead({
title: "فایل ها"
})
</script>

<style scoped lang="scss">
</style>
13 changes: 11 additions & 2 deletions frontend/pages/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<NuxtLink :to="`/dashboard/articles/edit/${article.uuid}`" class="btn mx-1 btn-sm btn-primary">
<span class="fa fa-pen"></span>
</NuxtLink>
<button type="button" class="btn mx-1 btn-sm btn-danger">
<button @click.prevent="deleteArticle(article.uuid)" type="button" class="btn mx-1 btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
</td>
Expand All @@ -65,7 +65,7 @@
</div>
</template>

<script setup>
<script lang="ts" setup>
definePageMeta({
layout: 'dashboard',
})
Expand All @@ -75,4 +75,13 @@ const { data, pending, error } = await useAsyncData(
useDashboardArticles().index
)
async function deleteArticle(uuid:string) {
if (!confirm('آیا میخواهید این مقاله را حذف کنید؟')) {
return
}
await useDashboardArticles().delete(uuid)
data.value.items = data.value.items.filter((article) => article.uuid != uuid)
}
</script>
Loading

0 comments on commit 9e52ea4

Please sign in to comment.