diff --git a/package-lock.json b/package-lock.json
index 76ad679..411029b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6824,6 +6824,11 @@
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=",
"dev": true
},
+ "izitoast": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/izitoast/-/izitoast-1.4.0.tgz",
+ "integrity": "sha512-Oc1X2wiQtPp39i5VpIjf3GJf5sfCtHKXZ5szx7RareyEeFLUlcEW0FSfBni28+Ul6KNKZRKzhVuWzSP4Xngh0w=="
+ },
"javascript-stringify": {
"version": "2.1.0",
"resolved": "https://registry.nlark.com/javascript-stringify/download/javascript-stringify-2.1.0.tgz",
diff --git a/package.json b/package.json
index 69fd989..4a81eb7 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"axios": "^0.21.4",
"bootstrap": "^4.6.0",
"core-js": "^3.6.5",
+ "izitoast": "^1.4.0",
"jquery": "^3.6.0",
"meta-router": "^4.0.1",
"popper.js": "^1.16.1",
diff --git a/src/abstraction/repository/programRepository.js b/src/abstraction/repository/programRepository.js
new file mode 100644
index 0000000..e358047
--- /dev/null
+++ b/src/abstraction/repository/programRepository.js
@@ -0,0 +1,15 @@
+import axios from "axios";
+import url from "@/router/url";
+import {
+ getArray,
+} from "../resources/programResource";
+export default class ProgramRepository {
+ async index() {
+ let response = await axios.get(url("indexProgram"), {
+ headers: { 'accept-language': 'en' },
+ });
+ if (response.status === 200) {
+ return getArray(response.data);
+ }
+ }
+}
diff --git a/src/abstraction/resources/programResource.js b/src/abstraction/resources/programResource.js
new file mode 100644
index 0000000..560a1f9
--- /dev/null
+++ b/src/abstraction/resources/programResource.js
@@ -0,0 +1,22 @@
+import { SetPagination } from "@/utils/setQueriesObject";
+import { getJsonTrainer } from './trainerProgramResource';
+import { getJsonSportCategory } from './sportCategoryPorgramResource';
+export const getJson = (data) => ({
+ id: data.id,
+ trainer: data.trainer ? getJsonTrainer(data.trainer) : {},
+ sport_category: data.trainer ? getJsonSportCategory(data.trainer) : {},
+ sport_category_id: data.sport_category_id,
+ status: data.status,
+ title: data.title,
+ description: data.description,
+ created_at: data.created_at,
+ updated_at: data.updated_at,
+ series_count: data.series_count
+});
+
+export const getArray = ({ data, meta }) => {
+ const pagination = SetPagination(meta);
+ data = data.map((program) => getJson(program));
+ return { data, pagination };
+};
+
diff --git a/src/abstraction/resources/sportCategoryPorgramResource.js b/src/abstraction/resources/sportCategoryPorgramResource.js
new file mode 100644
index 0000000..abc1163
--- /dev/null
+++ b/src/abstraction/resources/sportCategoryPorgramResource.js
@@ -0,0 +1,6 @@
+export const getJsonSportCategory = (data) => ({
+ id: data.sport_category.id,
+ name: data.sport_category.name,
+ local_name: data.sport_category.local_name,
+ language_id: data.sport_category.language_id,
+})
\ No newline at end of file
diff --git a/src/abstraction/resources/trainerProgramResource.js b/src/abstraction/resources/trainerProgramResource.js
new file mode 100644
index 0000000..f050427
--- /dev/null
+++ b/src/abstraction/resources/trainerProgramResource.js
@@ -0,0 +1,11 @@
+export const getJsonTrainer = (data) => ({
+ id: data.trainer.id,
+ first_name: data.trainer.first_name,
+ last_name: data.trainer.last_name,
+ birthday: data.trainer.birthday,
+ weight: data.trainer.weight,
+ height: data.trainer.height,
+ arm_diameter: data.trainer.arm_diameter,
+ leg_diameter: data.trainer.leg_diameter,
+ details: data.trainer.details
+})
\ No newline at end of file
diff --git a/src/components/Programs/Main.vue b/src/components/Programs/Main.vue
index 83378a3..dacfbd2 100644
--- a/src/components/Programs/Main.vue
+++ b/src/components/Programs/Main.vue
@@ -31,7 +31,14 @@
-
+
@@ -44,11 +51,22 @@ import ThirdImage from "../../assets/5595849.jpg";
import FourthImage from "../../assets/28-284379_photo-wallpaper-man-workout-gym-working-gym-workout.jpg";
import SectionTitle from "../Global/Section/SectionTitle.vue";
import ProgramItem from "./Item.vue";
+import { mapGetters, mapActions } from "vuex";
export default {
components: {
SectionTitle,
ProgramItem,
},
+ computed: {
+ ...mapGetters("programs", ["getPrograms"]),
+ },
+ methods: {
+ ...mapActions("programs", ["loadPrograms"]),
+ },
+ created() {
+ this.loadPrograms();
+ console.log("getPrograms", this.getPrograms);
+ },
data: () => ({
programs: [
{
diff --git a/src/main.js b/src/main.js
index 422662d..ed1561b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -7,7 +7,7 @@ import './utils/GlobalComponents';
import "./styles/global.scss";
import './mixins/Global.js';
import ApiService from '@/utils/axios/api';
-ApiService.init('https://www.champya-dev.ir');
+ApiService.init('https://app.champya-dev.ir');
import '@/utils/axios/errorHandler';
Vue.config.productionTip = false
diff --git a/src/router/url.js b/src/router/url.js
index c6e05d8..8b36ddc 100644
--- a/src/router/url.js
+++ b/src/router/url.js
@@ -1,7 +1,11 @@
import { urlGenerator } from "@/utils/urlGenerator";
const urls = {
- login: "auth/login"
+ login: "auth/login",
+ register: "auth/register",
+ resetPassword: "auth/forget-password",
+ logout: "auth/logout",
+ indexProgram: 'courses'
};
export default urlGenerator(urls);
diff --git a/src/store/modules/auth/actions.js b/src/store/modules/auth/actions.js
index 32e9980..30ddff7 100644
--- a/src/store/modules/auth/actions.js
+++ b/src/store/modules/auth/actions.js
@@ -1,5 +1,5 @@
import AuthRepository from "../../../abstraction/repository/authRepository";
-import {TokenStorage, UserStorage} from "@/utils/storage";
+import { TokenStorage, UserStorage } from "@/utils/storage";
import ApiService from "@/utils/axios/api";
function setTokenHeader(commit, response) {
@@ -10,7 +10,8 @@ function setTokenHeader(commit, response) {
}
export default {
- async login({commit}, data) {
+ async login({ commit }, data) {
+ console.log(data);
let repository = new AuthRepository();
const response = await repository.login(data);
if (response) {
@@ -25,7 +26,7 @@ export default {
TokenStorage.removeToken();
return true;
},
- async register({commit}, data) {
+ async register({ commit }, data) {
let repository = new AuthRepository();
const response = await repository.register(data);
setTokenHeader(commit, response);
diff --git a/src/store/modules/programs/actions.js b/src/store/modules/programs/actions.js
new file mode 100644
index 0000000..70af4b3
--- /dev/null
+++ b/src/store/modules/programs/actions.js
@@ -0,0 +1,15 @@
+import ProgramRepository from "@/abstraction/repository/programRepository";
+export default {
+ async loadPrograms({ state, commit }) {
+ try {
+ let data = { pagination: state.pagination };
+ let repository = new ProgramRepository();
+ const resource = await repository.index(data);
+ console.log(resource.data);
+ commit("SET_PROGRAMS", resource.data);
+ commit("SET_PAGINATION", resource.pagination);
+ } catch (e) {
+ return e;
+ }
+ },
+};
diff --git a/src/store/modules/programs/getters.js b/src/store/modules/programs/getters.js
new file mode 100644
index 0000000..f929a4c
--- /dev/null
+++ b/src/store/modules/programs/getters.js
@@ -0,0 +1,3 @@
+export default {
+ getPrograms: state => state.programs,
+};
diff --git a/src/store/modules/programs/mutations.js b/src/store/modules/programs/mutations.js
new file mode 100644
index 0000000..06612de
--- /dev/null
+++ b/src/store/modules/programs/mutations.js
@@ -0,0 +1,11 @@
+import Vue from "vue";
+export default {
+ SET_PROGRAMS(state, data) {
+ Vue.set(state, "programs", data);
+ },
+ SET_PAGINATION(state, pagination) {
+ pagination = { ...state.pagination, ...pagination };
+ Vue.set(state, "pagination", pagination);
+ },
+};
+
\ No newline at end of file
diff --git a/src/store/modules/programs/state.js b/src/store/modules/programs/state.js
new file mode 100644
index 0000000..4b09918
--- /dev/null
+++ b/src/store/modules/programs/state.js
@@ -0,0 +1,6 @@
+export default {
+ programs: [],
+ pagination: {
+ itemsPerPage: 12
+ },
+};
diff --git a/src/utils/axios/errorHandler.js b/src/utils/axios/errorHandler.js
index f97ab89..91a27ce 100644
--- a/src/utils/axios/errorHandler.js
+++ b/src/utils/axios/errorHandler.js
@@ -1,6 +1,6 @@
import axios from "axios";
import store from "@/store";
-// import toast from "../toast";
+import toast from "../toast";
import Vue from "vue";
import { TokenStorage } from "../storage";
import ApiService from "./api";
@@ -20,17 +20,17 @@ function errorResponseHandler(error) {
ApiService.removeAuthHeader();
store.commit('auth/logout', {}, { root: true });
window.location.href = '/';
- // toast.error('Wrong username or password.', 'Error');
+ toast.error('Wrong username or password.', 'Error');
} else if (error.response.status === 422) {
if (typeof error.response.data.errors !== 'undefined') {
for (const key in error.response.data.errors) {
if (Object.prototype.hasOwnProperty.call(error.response.data.errors, key)) {
- // toast.error(error.response.data.errors[key], 'Error');
+ toast.error(error.response.data.errors[key], 'Error');
}
}
}
} else if (error.response.status === 500) {
- // toast.error('Server Error', 'Error');
+ toast.error('Server Error', 'Error');
}
}
return Promise.reject(error);
@@ -38,7 +38,7 @@ function errorResponseHandler(error) {
function successHandler(response) {
if (response.status === 200 || response.status === 201) {
if (typeof response.data.message !== 'undefined' && typeof response.data.message.content !== 'undefined') {
- // toast.success(response.data.message.content, response.data.message.title || 'Success');
+ toast.success(response.data.message.content, response.data.message.title || 'Success');
}
}
return response;
diff --git a/src/utils/storage.js b/src/utils/storage.js
index f204d5d..0614b98 100644
--- a/src/utils/storage.js
+++ b/src/utils/storage.js
@@ -37,6 +37,7 @@ const UserStorage = {
save(user = null) {
user = qs.stringify(user);
localStorage.setItem(USER, user);
+ console.log('user saved');
},
remove() {
diff --git a/src/utils/toast.js b/src/utils/toast.js
new file mode 100644
index 0000000..b2861aa
--- /dev/null
+++ b/src/utils/toast.js
@@ -0,0 +1,23 @@
+import "izitoast/dist/css/iziToast.min.css";
+import iZtoast from "izitoast";
+
+const toast = {
+ error: (message, title = "Error") => {
+ return iZtoast.error({
+ title: title,
+ message: message,
+ rtl: true,
+ position: "bottomCenter"
+ });
+ },
+ success: (message, title = "Success") => {
+ return iZtoast.success({
+ title: title,
+ message: message,
+ rtl: true,
+ position: "bottomCenter"
+ });
+ }
+};
+
+export default toast;
\ No newline at end of file
diff --git a/src/utils/urlGenerator.js b/src/utils/urlGenerator.js
index 1c83ee8..35ab192 100644
--- a/src/utils/urlGenerator.js
+++ b/src/utils/urlGenerator.js
@@ -1,5 +1,5 @@
const urlGenerator = (urls) => {
- return function(routeAddress, parameters) {
+ return function (routeAddress, parameters) {
let urlPath = urls[routeAddress].split("/");
let newPath = [];
for (const iterator of urlPath) {
@@ -15,7 +15,7 @@ const urlGenerator = (urls) => {
newPath.push(iterator);
}
}
- return '/api/' + newPath.join("/");
+ return '/api/v1/' + newPath.join("/");
}
};
diff --git a/src/views/Login.vue b/src/views/Login.vue
index 6ebc911..8c5f4aa 100644
--- a/src/views/Login.vue
+++ b/src/views/Login.vue
@@ -45,10 +45,10 @@
@@ -105,10 +105,11 @@ export default {
methods: {
...mapActions("auth", ["login"]),
async doLogin() {
- const response = await this.login(this.form);
- if (response) {
- this.$router.push(this.$route.query.redirect || "/");
- }
+ console.log(this.form);
+ this.login(this.form);
+ // if (response) {
+ // this.$router.push(this.$route.query.redirect || "/");
+ // }
},
},
};
diff --git a/src/views/PasswordReset.vue b/src/views/PasswordReset.vue
index 71d4564..13d2f51 100644
--- a/src/views/PasswordReset.vue
+++ b/src/views/PasswordReset.vue
@@ -22,6 +22,8 @@
placeholder="your email address"
label="your email address"
class="no-error-msg"
+ dark
+ v-model="form.email"
>
@@ -33,6 +35,7 @@
height="25"
:text-mode="true"
text="send the code"
+ @click.native="resetPassword"
/>
@@ -62,9 +65,19 @@
diff --git a/src/views/Register.vue b/src/views/Register.vue
index 39299c6..6a789cc 100644
--- a/src/views/Register.vue
+++ b/src/views/Register.vue
@@ -20,17 +20,28 @@
placeholder="your email address"
label="your email address"
class="no-error-msg"
-
+ dark
+ v-model="form.email"
>
-
+
+
+
+
@@ -40,7 +51,8 @@
placeholder="password"
label="password"
class="no-error-msg"
-
+ dark
+ v-model="form.password"
>
@@ -50,7 +62,8 @@
placeholder="your password again"
label="your password again"
class="no-error-msg"
-
+ dark
+ v-model="form.password_confirmation"
>
@@ -63,6 +76,7 @@
height="25"
:text-mode="true"
text="do sign up"
+ @click.native="register(form)"
/>
@@ -107,9 +121,16 @@
\ No newline at end of file