Movida logica de obtener sesion a subpedido select + simplificado elegir pedido + mejores responses de session controller
This commit is contained in:
parent
354045c5df
commit
8488d9d6c5
4 changed files with 48 additions and 27 deletions
|
@ -3,13 +3,16 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Subpedido;
|
use App\Subpedido;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class SessionController extends Controller
|
class SessionController extends Controller
|
||||||
{
|
{
|
||||||
public function store(Request $request) {
|
public function store(Request $request): Response
|
||||||
|
{
|
||||||
$grupo_de_compra_id = Auth::user()->grupo_de_compra_id;
|
$grupo_de_compra_id = Auth::user()->grupo_de_compra_id;
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'id' => 'required',
|
'id' => 'required',
|
||||||
|
@ -19,11 +22,14 @@ class SessionController extends Controller
|
||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch() {
|
public function fetch(): JsonResponse
|
||||||
return session('pedido_id');
|
{
|
||||||
|
return response()->json(['id' => session('pedido_id')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy() {
|
public function destroy(): Response
|
||||||
|
{
|
||||||
session()->forget('pedido_id');
|
session()->forget('pedido_id');
|
||||||
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapGetters } from "vuex";
|
import { mapActions, mapGetters } from "vuex";
|
||||||
|
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
|
||||||
import PedidoSelectSection from "./PedidoSelectSection.vue";
|
import PedidoSelectSection from "./PedidoSelectSection.vue";
|
||||||
import Pedido from "./Pedido.vue";
|
import Pedido from "./Pedido.vue";
|
||||||
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { CartelPedidoAprobado, Pedido, Productos: Pedido, PedidoSelectSection },
|
components: { CartelPedidoAprobado, Pedido, Productos: Pedido, PedidoSelectSection },
|
||||||
|
@ -19,11 +19,9 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('productos',["init"]),
|
...mapActions('productos',["init"]),
|
||||||
...mapActions('pedido',["getSesion"]),
|
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.init();
|
await this.init();
|
||||||
await this.getSesion();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -11,21 +11,30 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-one-third buttons">
|
<div class="column is-one-third buttons">
|
||||||
<button class="button is-danger" v-if="!deshabilitado" @click="submit">Crear nuevo pedido
|
<button class="button is-danger" v-if="!deshabilitado" @click="submit(undefined)">
|
||||||
|
Crear nuevo pedido
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="pedidos.length" class="block">
|
<div v-if="pedidos.length" class="block">
|
||||||
<label class="label">Si ya comenzaste a hacer tu pedido este mes, elegilo en esta lista:</label>
|
<label class="label">
|
||||||
<p class="help">Podés seguir escribiendo en el campo de arriba para refinar la búsqueda.</p>
|
Si ya comenzaste a hacer tu pedido este mes, elegilo en esta lista:
|
||||||
<div class="columns is-mobile" v-for="(subpedidoExistente, index) in pedidos"
|
</label>
|
||||||
:class="{'has-background-grey-lighter': index % 2}" :key="index">
|
<p class="help">
|
||||||
|
Podés seguir escribiendo en el campo de arriba para refinar la búsqueda.
|
||||||
|
</p>
|
||||||
|
<div class="columns is-mobile"
|
||||||
|
v-for="(subpedidoExistente, index) in pedidos"
|
||||||
|
:class="{'has-background-grey-lighter': index % 2}"
|
||||||
|
:key="index">
|
||||||
<div class="column is-half-mobile is-two-thirds-desktop is-two-thirds-tablet">
|
<div class="column is-half-mobile is-two-thirds-desktop is-two-thirds-tablet">
|
||||||
<p style="padding-top: calc(.5em - 1px); margin-bottom: .5rem"
|
<p class="nombre">
|
||||||
v-text="subpedidoExistente.nombre"></p>
|
{{ subpedidoExistente.nombre }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons column is-half-mobile is-one-third-desktop is-one-third-tablet">
|
<div class="buttons column is-half-mobile is-one-third-desktop is-one-third-tablet">
|
||||||
<button class="button is-danger" @click="elegirPedido({ pedido: subpedidoExistente })">Continuar pedido
|
<button class="button is-danger" @click="submit(subpedidoExistente)">
|
||||||
|
Continuar pedido
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,11 +44,16 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapMutations, mapState } from "vuex";
|
import { mapActions, mapMutations, mapState } from "vuex";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'SubpedidoSelect',
|
name: 'SubpedidoSelect',
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.getGrupoDeCompra();
|
await this.getGrupoDeCompra();
|
||||||
|
const sesion = await axios.get("/pedido/sesion");
|
||||||
|
if (sesion.data.id) {
|
||||||
|
await this.elegirPedido({ pedido_id: sesion.data.id });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -64,9 +78,19 @@ export default {
|
||||||
}
|
}
|
||||||
this.getPedidos(this.searchString);
|
this.getPedidos(this.searchString);
|
||||||
},
|
},
|
||||||
async submit() {
|
async submit(pedido) {
|
||||||
await this.crearPedido({ nombre: this.searchString, grupo_de_compra_id: this.grupo_de_compra_id });
|
if (pedido)
|
||||||
|
await this.elegirPedido({ pedido_id: pedido.id });
|
||||||
|
else
|
||||||
|
await this.crearPedido({ nombre: this.searchString, grupo_de_compra_id: this.grupo_de_compra_id });
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.nombre {
|
||||||
|
padding-top: calc(.5em - 1px);
|
||||||
|
margin-bottom: .5rem
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
13
resources/js/store/modules/pedido.js
vendored
13
resources/js/store/modules/pedido.js
vendored
|
@ -47,13 +47,6 @@ const actions = {
|
||||||
async guardarSesion(_, { pedido_id }) {
|
async guardarSesion(_, { pedido_id }) {
|
||||||
await axios.post("/pedido/sesion", { id: pedido_id });
|
await axios.post("/pedido/sesion", { id: pedido_id });
|
||||||
},
|
},
|
||||||
async getSesion({ commit }) {
|
|
||||||
const sesion = await axios.get("/pedido/sesion");
|
|
||||||
if (sesion.data) {
|
|
||||||
const response = await axios.get(`/api/subpedidos/${sesion.data}`);
|
|
||||||
commit('setPedido', response.data.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async crearPedido({ commit, dispatch }, { nombre, grupo_de_compra_id }) {
|
async crearPedido({ commit, dispatch }, { nombre, grupo_de_compra_id }) {
|
||||||
const response = await axios.post("/api/subpedidos", {
|
const response = await axios.post("/api/subpedidos", {
|
||||||
nombre: nombre,
|
nombre: nombre,
|
||||||
|
@ -62,9 +55,9 @@ const actions = {
|
||||||
dispatch("guardarSesion", { pedido_id: response.data.data.id});
|
dispatch("guardarSesion", { pedido_id: response.data.data.id});
|
||||||
commit('setPedido', response.data.data);
|
commit('setPedido', response.data.data);
|
||||||
},
|
},
|
||||||
async elegirPedido({ commit, dispatch }, { pedido }) {
|
async elegirPedido({ commit, dispatch }, { pedido_id }) {
|
||||||
const response = await axios.get(`/api/subpedidos/${pedido.id}`);
|
const response = await axios.get(`/api/subpedidos/${pedido_id}`);
|
||||||
dispatch("guardarSesion", { pedido_id: response.data.data.id})
|
dispatch("guardarSesion", { pedido_id: pedido_id})
|
||||||
commit('setPedido', response.data.data);
|
commit('setPedido', response.data.data);
|
||||||
},
|
},
|
||||||
async modificarChismosa({ commit, dispatch }, { producto_id, cantidad, notas }) {
|
async modificarChismosa({ commit, dispatch }, { producto_id, cantidad, notas }) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue