Tipos para modulos de vuex
This commit is contained in:
parent
537bfd52ff
commit
7619196179
14 changed files with 244 additions and 69 deletions
|
@ -1,8 +1,8 @@
|
||||||
import Vue from '../../../node_modules/vue/dist/vue.esm.js';
|
import Vue from '../../../node_modules/vue/dist/vue.esm.js';
|
||||||
import Vuex from 'vuex';
|
import Vuex from 'vuex';
|
||||||
|
import login from "./modules/login";
|
||||||
import admin from "./modules/admin";
|
import admin from "./modules/admin";
|
||||||
import comisiones from "./modules/comisiones";
|
import comisiones from "./modules/comisiones";
|
||||||
import login from "./modules/login";
|
|
||||||
import pedido from "./modules/pedido";
|
import pedido from "./modules/pedido";
|
||||||
import productos from "./modules/productos";
|
import productos from "./modules/productos";
|
||||||
import ui from "./modules/ui";
|
import ui from "./modules/ui";
|
||||||
|
@ -11,9 +11,9 @@ Vue.use(Vuex);
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
|
login,
|
||||||
admin,
|
admin,
|
||||||
comisiones,
|
comisiones,
|
||||||
login,
|
|
||||||
pedido,
|
pedido,
|
||||||
productos,
|
productos,
|
||||||
ui,
|
ui,
|
|
@ -1,20 +1,21 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { AdminState } from "./types";
|
||||||
|
|
||||||
const state = {
|
const state: AdminState = {
|
||||||
lastFetch: null,
|
lastFetch: undefined,
|
||||||
grupo_de_compra_id: null,
|
grupo_de_compra_id: undefined,
|
||||||
nombre: null,
|
nombre: undefined,
|
||||||
devoluciones_habilitadas: null,
|
devoluciones_habilitadas: undefined,
|
||||||
pedidos: null,
|
pedidos: undefined,
|
||||||
total_a_recaudar: null,
|
total_a_recaudar: undefined,
|
||||||
total_sin_devoluciones: null,
|
total_sin_devoluciones: undefined,
|
||||||
total_barrial: null,
|
total_barrial: undefined,
|
||||||
total_devoluciones: null,
|
total_devoluciones: undefined,
|
||||||
total_de_pedido: null,
|
total_de_pedido: undefined,
|
||||||
total_a_transferir: null,
|
total_a_transferir: undefined,
|
||||||
total_transporte: null,
|
total_transporte: undefined,
|
||||||
cantidad_transporte: null,
|
cantidad_transporte: undefined,
|
||||||
saldo: null,
|
saldo: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
|
@ -59,7 +60,7 @@ const actions = {
|
||||||
|
|
||||||
const getters = {
|
const getters = {
|
||||||
grupoDeCompraDefinido() {
|
grupoDeCompraDefinido() {
|
||||||
return state.lastFetch !== null;
|
return state.lastFetch !== undefined;
|
||||||
},
|
},
|
||||||
hayPedidos() {
|
hayPedidos() {
|
||||||
return state.pedidos?.length > 0;
|
return state.pedidos?.length > 0;
|
45
resources/js/store/modules/admin/types.ts
Normal file
45
resources/js/store/modules/admin/types.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
export interface AdminState {
|
||||||
|
lastFetch?: Date,
|
||||||
|
grupo_de_compra_id: number,
|
||||||
|
nombre: string,
|
||||||
|
devoluciones_habilitadas: boolean,
|
||||||
|
pedidos: Pedido[],
|
||||||
|
total_a_recaudar: number,
|
||||||
|
total_sin_devoluciones: number,
|
||||||
|
total_barrial: number,
|
||||||
|
total_devoluciones: number,
|
||||||
|
total_de_pedido: number,
|
||||||
|
total_a_transferir: number,
|
||||||
|
total_transporte: number,
|
||||||
|
cantidad_transporte: number,
|
||||||
|
saldo: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Pedido {
|
||||||
|
id: number,
|
||||||
|
nombre: string,
|
||||||
|
productos: Producto[],
|
||||||
|
aprobado: boolean,
|
||||||
|
total: number,
|
||||||
|
total_transporte: number,
|
||||||
|
cantidad_transporte: number,
|
||||||
|
total_sin_devoluciones: number,
|
||||||
|
devoluciones_total: number,
|
||||||
|
devoluciones_notas: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Producto {
|
||||||
|
id: number,
|
||||||
|
fila: number,
|
||||||
|
nombre: string,
|
||||||
|
precio: number,
|
||||||
|
categoria: string,
|
||||||
|
bono: boolean,
|
||||||
|
created_at: Date,
|
||||||
|
updated_at: Date,
|
||||||
|
requiere_notas: boolean,
|
||||||
|
es_solidario: boolean,
|
||||||
|
notas: string,
|
||||||
|
cantidad: number,
|
||||||
|
total: number,
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { ComisionesState } from "./types";
|
||||||
|
|
||||||
const state = {
|
const state: ComisionesState = {
|
||||||
lastFetch: undefined,
|
lastFetch: undefined,
|
||||||
grupos_de_compra: [],
|
grupos_de_compra: [],
|
||||||
};
|
};
|
10
resources/js/store/modules/comisiones/types.ts
Normal file
10
resources/js/store/modules/comisiones/types.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
export interface ComisionesState {
|
||||||
|
lastFetch?: Date,
|
||||||
|
grupos_de_compra: Barrio[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Barrio {
|
||||||
|
id: number,
|
||||||
|
nombre: string,
|
||||||
|
saldo: number,
|
||||||
|
}
|
14
resources/js/store/modules/comunes.ts
Normal file
14
resources/js/store/modules/comunes.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
export type Rol = 'barrio' | 'admin_barrio' | 'comision';
|
||||||
|
|
||||||
|
export type UrlRol = 'pedido' | 'admin' | 'comisiones';
|
||||||
|
|
||||||
|
export type Response<T> = Axios.IPromise<Axios.AxiosXHR<T>>;
|
||||||
|
|
||||||
|
export interface UserRol {
|
||||||
|
rol: Rol
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Filtro {
|
||||||
|
clave: string,
|
||||||
|
valor: string,
|
||||||
|
}
|
|
@ -1,22 +1,24 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { Barrio, Estilos, LoginState, OpcionLogin, Textos } from "./types";
|
||||||
|
import { Response, UrlRol, UserRol } from "../comunes";
|
||||||
|
|
||||||
const state = {
|
const state: LoginState = {
|
||||||
regiones: null,
|
regiones: [],
|
||||||
grupos_de_compra: null,
|
grupos_de_compra: [],
|
||||||
region_elegida: null,
|
region_elegida: undefined,
|
||||||
grupo_de_compra_elegido: null,
|
grupo_de_compra_elegido: undefined,
|
||||||
rol: null,
|
rol: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
setRegiones(state, { regiones }) {
|
setRegiones(state, { regiones }): void {
|
||||||
state.regiones = regiones;
|
state.regiones = regiones;
|
||||||
},
|
},
|
||||||
setRegionYBarrios(state, { region, grupos_de_compra }) {
|
setRegionYBarrios(state, { region, grupos_de_compra }): void {
|
||||||
state.region_elegida = region;
|
state.region_elegida = region;
|
||||||
state.grupos_de_compra = grupos_de_compra;
|
state.grupos_de_compra = grupos_de_compra;
|
||||||
},
|
},
|
||||||
selectGrupoDeCompra(state, { grupo_de_compra }) {
|
selectGrupoDeCompra(state, { grupo_de_compra }): void {
|
||||||
state.grupo_de_compra_elegido = grupo_de_compra;
|
state.grupo_de_compra_elegido = grupo_de_compra;
|
||||||
},
|
},
|
||||||
setRol(state, { rol }) {
|
setRol(state, { rol }) {
|
||||||
|
@ -25,29 +27,29 @@ const mutations = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
async getRegiones({ commit }) {
|
async getRegiones({ commit }): Promise<void> {
|
||||||
const response = await axios.get("/api/regiones");
|
const response: Response<string[]> = await axios.get("/api/regiones");
|
||||||
commit('setRegiones', { regiones: response.data });
|
commit('setRegiones', { regiones: response.data });
|
||||||
},
|
},
|
||||||
async selectRegion({ commit }, { region }) {
|
async selectRegion({ commit }, { region }): Promise<void> {
|
||||||
const response = await axios.get(`/api/regiones/${region}`);
|
const response: Response<Barrio[]> = await axios.get(`/api/regiones/${region}`);
|
||||||
commit('setRegionYBarrios', { region: region, grupos_de_compra: response.data });
|
commit('setRegionYBarrios', { region: region, grupos_de_compra: response.data });
|
||||||
},
|
},
|
||||||
async getRol({ commit }) {
|
async getRol({ commit }): Promise<void> {
|
||||||
const response = await axios.get("/user/rol");
|
const response: Response<UserRol> = await axios.get("/user/rol");
|
||||||
commit('setRol', { rol: response.data.rol });
|
commit('setRol', { rol: response.data.rol });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getters = {
|
const getters = {
|
||||||
urlRol() {
|
urlRol(): UrlRol {
|
||||||
let split = window.location.pathname
|
let split = window.location.pathname
|
||||||
.replace('login', '')
|
.replace('login', '')
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(x => x.length);
|
.filter(x => x.length);
|
||||||
return split[0] ?? 'pedido';
|
return split[0] ?? 'pedido';
|
||||||
},
|
},
|
||||||
textos() {
|
textos(): Textos {
|
||||||
let rol = getters.urlRol();
|
let rol = getters.urlRol();
|
||||||
switch (rol) {
|
switch (rol) {
|
||||||
case 'admin':
|
case 'admin':
|
||||||
|
@ -78,7 +80,7 @@ const getters = {
|
||||||
throw new Error("Url inválida");
|
throw new Error("Url inválida");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
estilos() {
|
estilos(): Estilos {
|
||||||
let rol = getters.urlRol();
|
let rol = getters.urlRol();
|
||||||
switch (rol) {
|
switch (rol) {
|
||||||
case 'admin':
|
case 'admin':
|
||||||
|
@ -103,7 +105,7 @@ const getters = {
|
||||||
throw new Error("Url inválida");
|
throw new Error("Url inválida");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
opcionesLogin() {
|
opcionesLogin(): OpcionLogin[] {
|
||||||
let rol = getters.urlRol();
|
let rol = getters.urlRol();
|
||||||
switch (rol) {
|
switch (rol) {
|
||||||
case 'admin':
|
case 'admin':
|
38
resources/js/store/modules/login/types.ts
Normal file
38
resources/js/store/modules/login/types.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { Rol } from "../comunes";
|
||||||
|
|
||||||
|
export interface LoginState {
|
||||||
|
regiones: string[],
|
||||||
|
grupos_de_compra: Barrio[],
|
||||||
|
region_elegida?: string,
|
||||||
|
grupo_de_compra_elegido?: Barrio,
|
||||||
|
rol?: Rol,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Textos {
|
||||||
|
titulo: string,
|
||||||
|
subtitlo: string,
|
||||||
|
password: string,
|
||||||
|
ayuda: string,
|
||||||
|
label: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Estilos {
|
||||||
|
fondo: string,
|
||||||
|
texto: string,
|
||||||
|
botones: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OpcionLogin {
|
||||||
|
nombre: string,
|
||||||
|
href: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Barrio {
|
||||||
|
id: number,
|
||||||
|
nombre: string,
|
||||||
|
region: string,
|
||||||
|
created_at: Date,
|
||||||
|
updated_at: Date,
|
||||||
|
devoluciones_habilitadas: boolean,
|
||||||
|
saldo: number,
|
||||||
|
}
|
|
@ -1,18 +1,19 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { PedidoState } from "./types";
|
||||||
|
|
||||||
const state = {
|
const state: PedidoState = {
|
||||||
lastFetch: null,
|
lastFetch: undefined,
|
||||||
grupo_de_compra: null,
|
grupo_de_compra: undefined,
|
||||||
pedido_id: null,
|
pedido_id: undefined,
|
||||||
nombre: null,
|
nombre: undefined,
|
||||||
productos: null,
|
productos: undefined,
|
||||||
aprobado: null,
|
aprobado: undefined,
|
||||||
total: null,
|
total: undefined,
|
||||||
total_transporte: null,
|
total_transporte: undefined,
|
||||||
cantidad_transporte: null,
|
cantidad_transporte: undefined,
|
||||||
total_sin_devoluciones: null,
|
total_sin_devoluciones: undefined,
|
||||||
devoluciones_total: null,
|
devoluciones_total: undefined,
|
||||||
devoluciones_notas: null,
|
devoluciones_notas: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
|
@ -33,17 +34,17 @@ const mutations = {
|
||||||
state.devoluciones_notas = pedido.devoluciones_notas;
|
state.devoluciones_notas = pedido.devoluciones_notas;
|
||||||
},
|
},
|
||||||
reset(state) {
|
reset(state) {
|
||||||
state.lastFetch = null;
|
state.lastFetch = undefined;
|
||||||
state.pedido_id = null;
|
state.pedido_id = undefined;
|
||||||
state.nombre = null;
|
state.nombre = undefined;
|
||||||
state.productos = null;
|
state.productos = undefined;
|
||||||
state.aprobado = null;
|
state.aprobado = undefined;
|
||||||
state.total = null;
|
state.total = undefined;
|
||||||
state.total_transporte = null;
|
state.total_transporte = undefined;
|
||||||
state.cantidad_transporte = null;
|
state.cantidad_transporte = undefined;
|
||||||
state.total_sin_devoluciones = null;
|
state.total_sin_devoluciones = undefined;
|
||||||
state.devoluciones_total = null;
|
state.devoluciones_total = undefined;
|
||||||
state.devoluciones_notas = null;
|
state.devoluciones_notas = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,7 +104,7 @@ const actions = {
|
||||||
|
|
||||||
const getters = {
|
const getters = {
|
||||||
pedidoDefinido() {
|
pedidoDefinido() {
|
||||||
return state.lastFetch !== null;
|
return state.lastFetch !== undefined;
|
||||||
},
|
},
|
||||||
enChismosa() {
|
enChismosa() {
|
||||||
return ((producto_id) => state.productos.some(p => p.id === producto_id));
|
return ((producto_id) => state.productos.some(p => p.id === producto_id));
|
22
resources/js/store/modules/pedido/types.ts
Normal file
22
resources/js/store/modules/pedido/types.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { Producto } from "../admin/types";
|
||||||
|
|
||||||
|
export interface PedidoState {
|
||||||
|
lastFetch?: Date,
|
||||||
|
grupo_de_compra: Barrio,
|
||||||
|
pedido_id: number,
|
||||||
|
nombre: string,
|
||||||
|
productos: Producto[],
|
||||||
|
aprobado: boolean,
|
||||||
|
total: number,
|
||||||
|
total_transporte: number,
|
||||||
|
cantidad_transporte: number,
|
||||||
|
total_sin_devoluciones: number,
|
||||||
|
devoluciones_total: number,
|
||||||
|
devoluciones_notas: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Barrio {
|
||||||
|
id: number,
|
||||||
|
nombre: string,
|
||||||
|
devoluciones_habilitadas: boolean,
|
||||||
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { ProductosState } from "./types";
|
||||||
|
|
||||||
const state = {
|
const state: ProductosState = {
|
||||||
lastFetch: null,
|
lastFetch: undefined,
|
||||||
categorias: [],
|
categorias: [],
|
||||||
productos: [],
|
productos: [],
|
||||||
filtro: null,
|
filtro: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
|
@ -33,7 +34,7 @@ const actions = {
|
||||||
},
|
},
|
||||||
async getProductos({ commit }) {
|
async getProductos({ commit }) {
|
||||||
const response = await axios.get("/api/productos");
|
const response = await axios.get("/api/productos");
|
||||||
commit('setFiltro', null);
|
commit('setFiltro', undefined);
|
||||||
commit('setProductos', response.data.data);
|
commit('setProductos', response.data.data);
|
||||||
},
|
},
|
||||||
async seleccionarCategoria({ dispatch }, { categoria }) {
|
async seleccionarCategoria({ dispatch }, { categoria }) {
|
18
resources/js/store/modules/productos/types.ts
Normal file
18
resources/js/store/modules/productos/types.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { Filtro } from "../comunes";
|
||||||
|
|
||||||
|
export interface ProductosState {
|
||||||
|
lastFetch?: Date,
|
||||||
|
categorias: string[],
|
||||||
|
productos: Producto[],
|
||||||
|
filtro: Filtro,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Producto {
|
||||||
|
id: number,
|
||||||
|
nombre: string,
|
||||||
|
precio: number,
|
||||||
|
categoria: string,
|
||||||
|
economia_solidaria: boolean,
|
||||||
|
nacional: boolean,
|
||||||
|
requiere_notas: boolean,
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
const state = {
|
import { UiState } from "./types";
|
||||||
|
|
||||||
|
const state: UiState = {
|
||||||
show_chismosa: false,
|
show_chismosa: false,
|
||||||
show_devoluciones: false,
|
show_devoluciones: false,
|
||||||
show_tags: true,
|
show_tags: true,
|
||||||
tags_interactuada: false,
|
tags_interactuada: false,
|
||||||
migas: [{ nombre: 'Pedidos', action: 'pedido/resetear' }],
|
migas: [{ nombre: 'Pedidos', action: 'pedido/resetear' }],
|
||||||
canasta_actual: null,
|
canasta_actual: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
20
resources/js/store/modules/ui/types.ts
Normal file
20
resources/js/store/modules/ui/types.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
export interface UiState {
|
||||||
|
show_chismosa: boolean,
|
||||||
|
show_devoluciones: boolean,
|
||||||
|
show_tags: boolean,
|
||||||
|
tags_interactuada: boolean,
|
||||||
|
migas: Miga[],
|
||||||
|
canasta_actual?: DatosCanasta,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Miga {
|
||||||
|
nombre: string,
|
||||||
|
action: string,
|
||||||
|
arguments?: { [key: string]: string },
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DatosCanasta {
|
||||||
|
nombre: string,
|
||||||
|
fecha: Date,
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue