Skip to content

Commit

Permalink
fix: #133 display a subscription warning banner
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Aug 20, 2024
1 parent e46834b commit aa02cc7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 19 deletions.
4 changes: 1 addition & 3 deletions app/Http/Middleware/EnsureTeamSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public function handle(Request $request, Closure $next): Response

$doesntHaveSubscription = $subscription === null || ! $subscription->valid();
if ($doesntHaveSubscription) {
session()->flash('error', 'You must have a valid subscription to access this resource.');

return redirect()->route('teams.billing.show', $team);
return redirect()->route('teams.billing.show', $team)->warningBanner('You must have a valid subscription to access this resource.');
}

return $next($request);
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
Integration::handles($exceptions);
})
->withSchedule(function (Schedule $schedule) {
if (! app()->runningConsoleCommand('schedule:run') && ! app()->runningConsoleCommand('schedule:work')) {
if (! app()->runningConsoleCommand('schedule:run', 'schedule:work')) {
return;
}

Expand Down
102 changes: 87 additions & 15 deletions resources/js/Components/Banner.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,86 @@
<script setup>
import { ref, watchEffect } from 'vue';
import { usePage } from '@inertiajs/vue3';
import { ref, watchEffect } from "vue";
import { usePage } from "@inertiajs/vue3";
const page = usePage();
const show = ref(true);
const style = ref('success');
const message = ref('');
const style = ref("success");
const message = ref("");
watchEffect(async () => {
style.value = page.props.jetstream.flash?.bannerStyle || 'success';
message.value = page.props.jetstream.flash?.banner || '';
style.value = page.props.jetstream.flash?.bannerStyle || "success";
message.value = page.props.jetstream.flash?.banner || "";
show.value = true;
});
</script>
<template>
<div>
<div v-if="show && message" :class="{ 'bg-indigo-500': style == 'success', 'bg-red-700': style == 'danger' }">
<div
v-if="show && message"
:class="{
'bg-indigo-500': style == 'success',
'bg-yellow-500': style == 'warning',
'bg-red-700': style == 'danger',
}"
>
<div class="max-w-screen-xl mx-auto py-2 px-3 sm:px-6 lg:px-8">
<div class="flex items-center justify-between flex-wrap">
<div class="w-0 flex-1 flex items-center min-w-0">
<span class="flex p-2 rounded-lg" :class="{ 'bg-indigo-600': style == 'success', 'bg-red-600': style == 'danger' }">
<svg v-if="style == 'success'" class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
<span
class="flex p-2 rounded-lg"
:class="{
'bg-indigo-600': style == 'success',
'bg-yellow-600': style == 'warning',
'bg-red-600': style == 'danger',
}"
>
<svg
v-if="style == 'success'"
class="h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<svg
v-if="style == 'warning'"
class="h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
/>
</svg>
<svg v-if="style == 'danger'" class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" />
<svg
v-if="style == 'danger'"
class="h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"
/>
</svg>
</span>
Expand All @@ -39,12 +93,30 @@ watchEffect(async () => {
<button
type="button"
class="-me-1 flex p-2 rounded-md focus:outline-none sm:-me-2 transition"
:class="{ 'hover:bg-indigo-600 focus:bg-indigo-600': style == 'success', 'hover:bg-red-600 focus:bg-red-600': style == 'danger' }"
:class="{
'hover:bg-indigo-600 focus:bg-indigo-600':
style == 'success',
'hover:bg-yellow-600 focus:bg-yellow-600':
style == 'warning',
'hover:bg-red-600 focus:bg-red-600':
style == 'danger',
}"
aria-label="Dismiss"
@click.prevent="show = false"
>
<svg class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
<svg
class="h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
Expand Down

0 comments on commit aa02cc7

Please sign in to comment.