diff --git a/src/auth/router.js b/src/auth/router.js
index 46d127a..48ce281 100644
--- a/src/auth/router.js
+++ b/src/auth/router.js
@@ -73,35 +73,37 @@ const hasPermission = (requiredPermissions = []) => {
);
};
-router.beforeEach((to, from, next) => {
- if (to.meta.title) {
- document.title = to.meta.title;
- }
+// router.beforeEach((to, from, next) => {
+// if (to.meta.title) {
+// document.title = to.meta.title;
+// }
- // if (to.matched.some((record) => record.meta.requiresAuth)) {
- if (!isAuthenticated()) {
- next({
- path: "/login",
- query: { redirect: to.fullPath },
- });
+// console.log(to, from);
- return;
- }
+// // if (to.matched.some((record) => record.meta.requiresAuth)) {
+// if (!isAuthenticated()) {
+// next({
+// path: "/login",
+// });
- // const requiredPermissions = to.meta.permissions || [];
+// return;
+// }
- // if (requiredPermissions.length > 0 && !hasPermission(requiredPermissions)) {
- // next({ path: "/unauthorized" });
+// // const requiredPermissions = to.meta.permissions || [];
- // return;
- // }
- // }
+// // if (requiredPermissions.length > 0 && !hasPermission(requiredPermissions)) {
+// // next({ path: "/unauthorized" });
- // if (to.matched.some((record) => record.meta.guest) && isAuthenticated()) {
- // next({ path: "/" });
+// // return;
+// // }
+// // }
- // return;
- // }
+// // if (to.matched.some((record) => record.meta.guest) && isAuthenticated()) {
+// // next({ path: "/" });
- next();
-});
+// // return;
+// // }
+
+// next();
+// return;
+// });
diff --git a/src/components/Button/index.vue b/src/components/Button/index.vue
index ea5f0f8..dfd9541 100644
--- a/src/components/Button/index.vue
+++ b/src/components/Button/index.vue
@@ -7,6 +7,7 @@
:type="type"
:disable="loading || disabled"
:text-color="textColor"
+ :full-width="fullWidth"
/>
diff --git a/src/components/Table/index.vue b/src/components/Table/index.vue
index d77621c..949a735 100644
--- a/src/components/Table/index.vue
+++ b/src/components/Table/index.vue
@@ -6,7 +6,6 @@
:columns="columns"
:row-key="rowKey"
:loading="loading"
- row-key="name"
flat
bordered
virtual-scroll
@@ -24,7 +23,7 @@
- Mostrando {{ pagination.currentPage }} de
- {{ pagination.totalItems }}
+ Total: {{ pagination.total }}
@@ -61,6 +57,11 @@ export default {
required: false,
default: "name",
},
+ rowKey: {
+ type: String,
+ required: false,
+ default: "id",
+ },
title: {
type: String,
required: false,
@@ -86,6 +87,7 @@ export default {
return {
columns: props.columns,
rows: props.rows,
+ rowKey: props.rowKey,
};
},
};
diff --git a/src/components/TextField/index.vue b/src/components/TextField/index.vue
index de754e1..2e46e99 100644
--- a/src/components/TextField/index.vue
+++ b/src/components/TextField/index.vue
@@ -1,5 +1,5 @@
-
+
{{ label }} {{ required ? "*" : "" }}
diff --git a/src/config/axios.js b/src/config/axios.js
index 03df154..1134877 100644
--- a/src/config/axios.js
+++ b/src/config/axios.js
@@ -17,3 +17,15 @@ API.interceptors.request.use((config) => {
return config;
});
+
+API.interceptors.response.use(
+ (response) => response,
+ (error) => {
+ if (error.response.status === 401) {
+ Cookies.remove("token");
+ window.location.href = "/login";
+ }
+
+ return Promise.reject(error);
+ }
+);
diff --git a/src/main.js b/src/main.js
index 4c447a6..02ebe30 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,5 +1,5 @@
import { createApp } from "vue";
-import { Quasar } from "quasar";
+import { Notify, Quasar } from "quasar";
import quasarLang from "quasar/lang/pt-BR";
@@ -21,7 +21,7 @@ app.use(Quasar, {
config: {
dark: "auto",
},
- plugins: {},
+ plugins: { Notify },
lang: quasarLang,
});
diff --git a/src/routes/videos/index.vue b/src/routes/videos/index.vue
index 9406953..7d5f0b7 100644
--- a/src/routes/videos/index.vue
+++ b/src/routes/videos/index.vue
@@ -1,26 +1,42 @@
-
-
-
+
-
-
-
+
-
+
- Infelizmente, não há dados para serem mostrados
+ Não há vídeos
@@ -31,42 +47,16 @@
import Button from "@components/Button";
import Table from "@components/Table";
import TextField from "@components/TextField";
+
import { API } from "@config/axios";
+import { getErrorMessage } from "@utils/axios";
const columns = [
{
- name: "name",
- required: true,
- label: "Dessert (100g serving)",
+ name: "id",
+ label: "Identificador",
align: "left",
- field: (row) => row.name,
- format: (val) => `${val}`,
- sortable: true,
- },
- {
- name: "calories",
- align: "center",
- label: "Calories",
- field: "calories",
- sortable: true,
- },
- { name: "fat", label: "Fat (g)", field: "fat", sortable: true },
- { name: "carbs", label: "Carbs (g)", field: "carbs" },
- { name: "protein", label: "Protein (g)", field: "protein" },
- { name: "sodium", label: "Sodium (mg)", field: "sodium" },
- {
- name: "calcium",
- label: "Calcium (%)",
- field: "calcium",
- sortable: true,
- sort: (a, b) => parseInt(a, 10) - parseInt(b, 10),
- },
- {
- name: "iron",
- label: "Iron (%)",
- field: "iron",
- sortable: true,
- sort: (a, b) => parseInt(a, 10) - parseInt(b, 10),
+ field: "id",
},
];
@@ -81,21 +71,31 @@ export default {
return {
columns,
rows: [],
+ loading: false,
pagination: {
- currentPage: 1,
+ page: 1,
totalPages: 1,
- totalItems: 10,
+ total: 10,
+ perPage: 10,
},
};
},
methods: {
async handleSearch() {
try {
+ this.loading = true;
+
const { data } = await API.get("/videos");
- console.log(data);
+ this.rows = data.content;
+ this.pagination = data.pagination;
} catch (error) {
- console.log(error);
+ this.$q.notify({
+ type: "negative",
+ message: getErrorMessage(error, "Erro ao buscar vídeos"),
+ });
+ } finally {
+ this.loading = false;
}
},
},
diff --git a/src/utils/axios.js b/src/utils/axios.js
new file mode 100644
index 0000000..854b72b
--- /dev/null
+++ b/src/utils/axios.js
@@ -0,0 +1,9 @@
+import { isAxiosError } from "axios";
+
+export function getErrorMessage(error, defaultMessage = "Erro inesperado") {
+ if (isAxiosError(error)) {
+ return error.response.data.message;
+ }
+
+ return error?.message ?? defaultMessage;
+}