Moved to _dev
This commit is contained in:
123
crater/resources/scripts/customer/stores/auth.js
Normal file
123
crater/resources/scripts/customer/stores/auth.js
Normal file
@@ -0,0 +1,123 @@
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import router from '@/scripts/customer/customer-router'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { global } = window.i18n
|
||||
|
||||
export const useAuthStore = defineStore({
|
||||
id: 'customerAuth',
|
||||
state: () => ({
|
||||
loginData: {
|
||||
email: '',
|
||||
password: '',
|
||||
device_name: 'xyz',
|
||||
company: '',
|
||||
},
|
||||
}),
|
||||
|
||||
actions: {
|
||||
login(data) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get('/sanctum/csrf-cookie').then((response) => {
|
||||
if (response) {
|
||||
axios
|
||||
.post(`/${data.company}/customer/login`, data)
|
||||
.then((response) => {
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.tm('general.login_successfully'),
|
||||
})
|
||||
resolve(response)
|
||||
setTimeout(() => {
|
||||
this.loginData.email = ''
|
||||
this.loginData.password = ''
|
||||
}, 1000)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
forgotPassword(data) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/api/v1/${data.company}/customer/auth/password/email`, data)
|
||||
|
||||
.then((response) => {
|
||||
if (response.data) {
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.tm('general.send_mail_successfully'),
|
||||
})
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status === 403) {
|
||||
notificationStore.showNotification({
|
||||
type: 'error',
|
||||
message: global.tm('errors.email_could_not_be_sent'),
|
||||
})
|
||||
} else {
|
||||
handleError(err)
|
||||
}
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
resetPassword(data, company) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/api/v1/${company}/customer/auth/reset/password`, data)
|
||||
|
||||
.then((response) => {
|
||||
if (response.data) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.tm('login.password_reset_successfully'),
|
||||
})
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response && err.response.status === 403) {
|
||||
notificationStore.showNotification({
|
||||
type: 'error',
|
||||
message: global.tm('validation.email_incorrect'),
|
||||
})
|
||||
}
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
logout(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/${data}/customer/logout`)
|
||||
.then((response) => {
|
||||
const notificationStore = useNotificationStore()
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.tm('general.logged_out_successfully'),
|
||||
})
|
||||
router.push({ name: 'customer.login' })
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
14
crater/resources/scripts/customer/stores/customer.js
Normal file
14
crater/resources/scripts/customer/stores/customer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { defineStore } = window.pinia
|
||||
|
||||
export const useCustomerStore = defineStore({
|
||||
id: 'customers',
|
||||
state: () => ({
|
||||
customers: 'okay',
|
||||
}),
|
||||
|
||||
actions: {
|
||||
resetCustomers() {
|
||||
this.customers = 'okay'
|
||||
},
|
||||
}
|
||||
})
|
||||
43
crater/resources/scripts/customer/stores/dashboard.js
Normal file
43
crater/resources/scripts/customer/stores/dashboard.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { defineStore } = window.pinia
|
||||
import { useGlobalStore } from '@/scripts/customer/stores/global'
|
||||
import axios from 'axios'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
|
||||
export const useDashboardStore = defineStore({
|
||||
id: 'dashboard',
|
||||
state: () => ({
|
||||
recentInvoices: [],
|
||||
recentEstimates: [],
|
||||
invoiceCount: 0,
|
||||
estimateCount: 0,
|
||||
paymentCount: 0,
|
||||
totalDueAmount: [],
|
||||
isDashboardDataLoaded: false,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
loadData(data) {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${globalStore.companySlug}/customer/dashboard`, {
|
||||
data,
|
||||
})
|
||||
.then((response) => {
|
||||
this.totalDueAmount = response.data.due_amount
|
||||
this.estimateCount = response.data.estimate_count
|
||||
this.invoiceCount = response.data.invoice_count
|
||||
this.paymentCount = response.data.payment_count
|
||||
this.recentInvoices = response.data.recentInvoices
|
||||
this.recentEstimates = response.data.recentEstimates
|
||||
globalStore.getDashboardDataLoaded = true
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
116
crater/resources/scripts/customer/stores/estimate.js
Normal file
116
crater/resources/scripts/customer/stores/estimate.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const { defineStore } = window.pinia
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import axios from 'axios'
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
|
||||
export const useEstimateStore = defineStore({
|
||||
id: 'customerEstimateStore',
|
||||
state: () => ({
|
||||
estimates: [],
|
||||
totalEstimates: 0,
|
||||
selectedViewEstimate: [],
|
||||
}),
|
||||
actions: {
|
||||
fetchEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/estimates`, { params })
|
||||
.then((response) => {
|
||||
this.estimates = response.data.data
|
||||
this.totalEstimates = response.data.meta.estimateTotalCount
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchViewEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/estimates/${params.id}`, {
|
||||
params,
|
||||
})
|
||||
|
||||
.then((response) => {
|
||||
this.selectedViewEstimate = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
searchEstimate(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/estimates`, { params })
|
||||
.then((response) => {
|
||||
this.estimates = response.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
acceptEstimate({ slug, id, status }) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
|
||||
.then((response) => {
|
||||
let pos = this.estimates.findIndex(
|
||||
(estimate) => estimate.id === id
|
||||
)
|
||||
if (this.estimates[pos]) {
|
||||
this.estimates[pos].status = 'ACCEPTED'
|
||||
|
||||
const notificationStore = useNotificationStore(true)
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.t('estimates.marked_as_accepted_message'),
|
||||
})
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
rejectEstimate({ slug, id, status }) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/api/v1/${slug}/customer/estimate/${id}/status`, { status })
|
||||
.then((response) => {
|
||||
let pos = this.estimates.findIndex(
|
||||
(estimate) => estimate.id === id
|
||||
)
|
||||
if (this.estimates[pos]) {
|
||||
this.estimates[pos].status = 'REJECTED'
|
||||
|
||||
const notificationStore = useNotificationStore(true)
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: global.t('estimates.marked_as_rejected_message'),
|
||||
})
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
62
crater/resources/scripts/customer/stores/global.js
Normal file
62
crater/resources/scripts/customer/stores/global.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
import { useUserStore } from './user'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
export const useGlobalStore = defineStore({
|
||||
id: 'CustomerPortalGlobalStore',
|
||||
state: () => ({
|
||||
languages: [],
|
||||
currency: null,
|
||||
isAppLoaded: false,
|
||||
countries: [],
|
||||
getDashboardDataLoaded: false,
|
||||
currentUser: null,
|
||||
companySlug: '',
|
||||
mainMenu: null,
|
||||
enabledModules: []
|
||||
}),
|
||||
|
||||
actions: {
|
||||
bootstrap(data) {
|
||||
this.companySlug = data
|
||||
const userStore = useUserStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${data}/customer/bootstrap`)
|
||||
.then((response) => {
|
||||
this.currentUser = response.data.data
|
||||
this.mainMenu = response.data.meta.menu
|
||||
this.currency = response.data.data.currency
|
||||
this.enabledModules = response.data.meta.modules
|
||||
Object.assign(userStore.userForm, response.data.data)
|
||||
window.i18n.locale = response.data.default_language
|
||||
this.isAppLoaded = true
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchCountries() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.countries.length) {
|
||||
resolve(this.countries)
|
||||
} else {
|
||||
axios
|
||||
.get(`/api/v1/${this.companySlug}/customer/countries`)
|
||||
.then((response) => {
|
||||
this.countries = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
62
crater/resources/scripts/customer/stores/invoice.js
Normal file
62
crater/resources/scripts/customer/stores/invoice.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
export const useInvoiceStore = defineStore({
|
||||
id: 'customerInvoiceStore',
|
||||
state: () => ({
|
||||
totalInvoices: 0,
|
||||
invoices: [],
|
||||
selectedViewInvoice: [],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
fetchInvoices(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data.data
|
||||
this.totalInvoices = response.data.meta.invoiceTotalCount
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchViewInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices/${params.id}`, {
|
||||
params,
|
||||
})
|
||||
|
||||
.then((response) => {
|
||||
this.selectedViewInvoice = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
searchInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
75
crater/resources/scripts/customer/stores/payment.js
Normal file
75
crater/resources/scripts/customer/stores/payment.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
|
||||
export const usePaymentStore = defineStore({
|
||||
id: 'customerPaymentStore',
|
||||
state: () => ({
|
||||
payments: [],
|
||||
selectedViewPayment: [],
|
||||
totalPayments: 0,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
fetchPayments(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/payments`, { params })
|
||||
.then((response) => {
|
||||
this.payments = response.data.data
|
||||
this.totalPayments = response.data.meta.paymentTotalCount
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchViewPayment(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/payments/${params.id}`)
|
||||
|
||||
.then((response) => {
|
||||
this.selectedViewPayment = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
searchPayment(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/payments`, { params })
|
||||
.then((response) => {
|
||||
this.payments = response.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchPaymentModes(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/payment-method`, { params })
|
||||
.then((response) => {
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
78
crater/resources/scripts/customer/stores/user.js
Normal file
78
crater/resources/scripts/customer/stores/user.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import stubs from '@/scripts/customer/stubs/address'
|
||||
import axios from 'axios'
|
||||
import { useGlobalStore } from '@/scripts/customer/stores/global'
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: 'customerUserStore',
|
||||
|
||||
state: () => ({
|
||||
customers: [],
|
||||
userForm: {
|
||||
avatar: null,
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
company: '',
|
||||
confirm_password: '',
|
||||
billing: {
|
||||
...stubs,
|
||||
},
|
||||
shipping: {
|
||||
...stubs,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
actions: {
|
||||
copyAddress() {
|
||||
this.userForm.shipping = {
|
||||
...this.userForm.billing,
|
||||
type: 'shipping',
|
||||
}
|
||||
},
|
||||
|
||||
fetchCurrentUser() {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${globalStore.companySlug}/customer/me`)
|
||||
.then((response) => {
|
||||
Object.assign(this.userForm, response.data.data)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
updateCurrentUser({ data, message }) {
|
||||
const globalStore = useGlobalStore()
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(`/api/v1/${globalStore.companySlug}/customer/profile`, data)
|
||||
.then((response) => {
|
||||
this.userForm = response.data.data
|
||||
globalStore.currentUser = response.data.data
|
||||
resolve(response)
|
||||
|
||||
if (message) {
|
||||
const notificationStore = useNotificationStore(true)
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: message,
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user