Skip to content

Commit

Permalink
💄 Add Checkin Success Modal in experimental features (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin authored Sep 29, 2023
1 parent a200858 commit e4623f7
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/Dto/PointCalculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class PointCalculation
public readonly int $basePoints;
public readonly int $distancePoints;
public readonly PointReason $reason;
public readonly int $factor;
public readonly float $factor;

public function __construct(
int $points,
int $basePoints,
int $distancePoints,
PointReason $reason,
int $factor,
float $factor,
) {
$this->points = $points;
$this->basePoints = $basePoints;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Backend/BrouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static function getGeoJSONForRoute(
Log::debug('[RefreshPolyline] Brouter response was not okay.', ['body' => $response->body()]);
throw new InvalidArgumentException('Brouter response was not okay.');
}
throw new InvalidArgumentException('Brouter response was not okay.');

$geoJson = json_decode($response->body(), false, 512, JSON_THROW_ON_ERROR);
//remove unnecessary data
Expand Down
6 changes: 6 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "awesomplete/awesomplete";
import "leaflet/dist/leaflet.js";
import "./api/api";
import "./components/maps";
import CheckinSuccessHelper from "../vue/components/CheckinSuccessHelper.vue";

document.addEventListener("DOMContentLoaded", function () {

Expand All @@ -30,6 +31,11 @@ document.addEventListener("DOMContentLoaded", function () {
app3.component('Stationautocomplete', StationAutocomplete);
app3.mount('#station-board-new');

const app4 = createApp({});
app4.component('CheckinSuccessHelper', CheckinSuccessHelper);
app4.mount('#checkin-success-helper');


window.notyf = new Notyf({
duration: 5000,
position: { x: "right", y: "top" },
Expand Down
7 changes: 6 additions & 1 deletion resources/views/status.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-7">
<div class="col-md-8 col-lg-7" >
@if(auth()->user()->experimental ?? false)
<div id="checkin-success-helper">
<checkin-success-helper></checkin-success-helper>
</div>
@endif
<h2 class="fs-5">{{ userTime($status->trainCheckin->departure,__('dateformat.with-weekday')) }}</h2>
@include('includes.status')

Expand Down
29 changes: 25 additions & 4 deletions resources/vue/components/CheckinInterface.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import {DateTime} from "luxon";
import {Notyf} from "notyf";
export default {
name: "CheckinInterface",
Expand All @@ -21,6 +22,8 @@ export default {
visibility: 0,
business: 0,
loading: false,
notyf: new Notyf({position: {x: 'right', y: 'bottom'}}),
collision: false,
};
},
methods: {
Expand All @@ -38,7 +41,7 @@ export default {
destination: this.selectedDestination.evaIdentifier,
departure: DateTime.fromISO(this.selectedTrain.plannedWhen).setZone("UTC").toISO(),
arrival: DateTime.fromISO(this.selectedDestination.arrivalPlanned).setZone("UTC").toISO(),
force: false,
force: this.collision,
eventId: null,
};
fetch('/api/v1/trains/checkin', {
Expand All @@ -48,9 +51,27 @@ export default {
},
body: JSON.stringify(data),
}).then((response) => {
response.json().then((result) => {
window.location = "/status/" + result.data.status.id;
});
this.loading = false;
if (response.ok) {
response.json().then((result) => {
localStorage.setItem("points", JSON.stringify(result.data.points));
localStorage.setItem("alsoOnThisConnection", JSON.stringify(result.data.alsoOnThisConnection));
window.location = "/status/" + result.data.status.id;
});
}
if (response.status === 409) {
response.json().then(() => {
this.collision = true;
this.notyf.error("Du bist bereits in einem Zug eingecheckt. Falls du den Checkin forcieren möchtest, drücke nochmal auf \"einchecken\".");
});
}
if (response.status === 500) {
this.notyf.error("Ein unbekannter Fehler ist aufgetreten. Bitte versuche es später erneut.");
}
}).catch((reason) => {
console.log(reason);
this.loading = false;
this.notyf.error(reason);
});
}
},
Expand Down
60 changes: 60 additions & 0 deletions resources/vue/components/CheckinSuccessHelper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script>
import FullScreenModal from "./FullScreenModal.vue";
import ModalComponent from "./ModalComponent.vue";
export default {
name: "CheckinSuccessHelper",
components: {ModalComponent, FullScreenModal},
data() {
return {
points: {calculation: {}},
alsoOnThisConection: [],
};
},
methods: {
fetchData() {
this.points = JSON.parse(localStorage.getItem("points"));
this.alsoOnThisConection = JSON.parse(localStorage.getItem("alsoOnThisConnection"));
localStorage.removeItem("points");
localStorage.removeItem("alsoOnThisConnection");
console.log(this.alsoOnThisConection[0]);
if (this.points && this.points.points) {
this.$refs.modal.show();
}
}
},
mounted() {
this.fetchData();
}
}
</script>

<template>
<ModalComponent ref="modal" header-class="bg-success text-white" title="Erfolgreich eingecheckt!" :hide-footer="true">
<template #body>
<p>Für deinen Checkin erhältst du {{ points.points }} Punkte!</p>
<p v-if="points.calculation.reason === 1 || points.calculation.reason === 2" class="text-muted">
Du hast zu weit vor/nach deiner Fahrt eingecheckt. Ansonsten hättest du {{ points.points / points.calculation.factor }} Punkte bekommen.
</p>
<p v-if="points.calculation.reason === 3" class="text-danger">Da du deinen Checkin forciert hast, bekommst du keine Punkte.</p>

<template v-if="alsoOnThisConection.length > 0">
<h5 class="mt-5">In deiner Verbindung haben folgende Leute eingecheckt:</h5>
<div class="list-group">
<a href="#" v-for="status in alsoOnThisConection" class="list-group-item list-group-item-action d-flex gap-3 py-3" aria-current="true">
<div class="d-flex gap-2 w-100 justify-content-between">
<div>
<h6 class="mb-0 fw-bold opacity-75">{{status.username}}<small class="text-muted">@HerrLevin_</small></h6>
<p class="mb-0">{{status.train.origin.name}} ➜ {{status.train.destination.name}}</p>
</div>
</div>
</a>
</div>
</template>
</template>
</ModalComponent>
</template>

<style scoped lang="scss">
</style>
8 changes: 6 additions & 2 deletions resources/vue/components/ModalComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default {
type: String,
default: null
},
headerClass: {
type: String,
default: null
},
dialogClass: {
type: String,
default: null
Expand Down Expand Up @@ -44,8 +48,8 @@ export default {
aria-hidden="true" ref="modalComponent">
<div class="modal-dialog" :class="dialogClass">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-dark" :class="{'flex-grow-1': !!this.$slots['header-extra']}">
<div class="modal-header text-dark" :class="headerClass">
<h5 class="modal-title" :class="{'flex-grow-1': !!this.$slots['header-extra']}">
{{ title }}
</h5>
<slot name="header-extra"/>
Expand Down

0 comments on commit e4623f7

Please sign in to comment.