Hide Fee button when no bill mode enabled

This commit is contained in:
philipp lang 2021-11-19 00:39:34 +01:00
parent 144487a881
commit e004bbfca1
8 changed files with 32 additions and 12 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use App\Http\Resources\UserResource; use App\Http\Resources\UserResource;
use App\Setting\GeneralSettings;
use Closure; use Closure;
use Session; use Session;
@ -14,6 +15,7 @@ class InertiaShareMiddleware
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Closure $next * @param \Closure $next
* @param GeneralSettings $settings
* @return mixed * @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
@ -32,7 +34,10 @@ class InertiaShareMiddleware
}, },
'title' => function() { 'title' => function() {
return session()->get('title', ''); return session()->get('title', '');
} },
'settings' => [
'modules' => app(GeneralSettings::class)->modules,
]
]); ]);
$response = $next($request); $response = $next($request);

View File

@ -18,10 +18,10 @@ class SettingController extends Controller
{ {
return Inertia::render('setting/Index', [ return Inertia::render('setting/Index', [
'options' => [ 'options' => [
'modes' => $generalSettings->modeOptions() 'modules' => $generalSettings->moduleOptions()
], ],
'general' => [ 'general' => [
'modes' => $generalSettings->modes 'modules' => $generalSettings->modules
] ]
]); ]);
} }

View File

@ -8,12 +8,14 @@ class GeneralSettings extends Settings
{ {
/** @var array<int, string> */ /** @var array<int, string> */
public array $modes; public array $modules;
public bool $single_view;
/** /**
* @return array<int, string> * @return array<int, string>
*/ */
public function modeOptions(): array public function moduleOptions(): array
{ {
return [ return [
'bill', 'bill',

View File

@ -13,10 +13,12 @@ class CreateGeneralSettings extends SettingsMigration
{ {
$defaults = [ $defaults = [
'diözese' => [ 'diözese' => [
'modes' => [] 'modules' => [],
'single_view' => false,
], ],
'stamm' => [ 'stamm' => [
'modes' => ['bill'] 'modules' => ['bill'],
'single_view' => true,
] ]
]; ];
@ -26,6 +28,7 @@ class CreateGeneralSettings extends SettingsMigration
public function up(): void public function up(): void
{ {
$defaults = $this->defaults(config('app.mode')); $defaults = $this->defaults(config('app.mode'));
$this->migrator->add('general.modes', $defaults['modes']); $this->migrator->add('general.modules', $defaults['modules']);
$this->migrator->add('general.single_view', $defaults['single_view']);
} }
} }

3
resources/js/app.js vendored
View File

@ -12,6 +12,7 @@ import Pages from './components/Pages.vue';
import VBool from './components/VBool.vue'; import VBool from './components/VBool.vue';
import App from './layouts/App.vue'; import App from './layouts/App.vue';
import VTooltip from 'v-tooltip' import VTooltip from 'v-tooltip'
import hasModule from './mixins/hasModule.js';
Vue.use(plugin) Vue.use(plugin)
Vue.use(VTooltip); Vue.use(VTooltip);
@ -25,6 +26,8 @@ Vue.component('v-bool', VBool);
const el = document.getElementById('app') const el = document.getElementById('app')
Vue.mixin(hasModule);
new Vue({ new Vue({
render: h => h(InertiaApp, { render: h => h(InertiaApp, {
props: { props: {

View File

@ -8,7 +8,7 @@
<div class="grid gap-2"> <div class="grid gap-2">
<v-link href="/" menu="dashboard" icon="loss">Dashboard</v-link> <v-link href="/" menu="dashboard" icon="loss">Dashboard</v-link>
<v-link href="/member" menu="member" icon="user">Mitglieder</v-link> <v-link href="/member" menu="member" icon="user">Mitglieder</v-link>
<v-link href="/subscription" menu="subscription" icon="money">Beiträge</v-link> <v-link href="/subscription" v-show="hasModule('bill')" menu="subscription" icon="money">Beiträge</v-link>
</div> </div>
</div> </div>

7
resources/js/mixins/hasModule.js vendored Normal file
View File

@ -0,0 +1,7 @@
export default {
methods: {
hasModule(module) {
return this.$page.props.settings.modules.indexOf(module) !== -1;
}
}
};

View File

@ -15,7 +15,7 @@ class GlobalSettingTest extends TestCase
public function testItLoadsGeneralSettings(): void public function testItLoadsGeneralSettings(): void
{ {
GeneralSettings::fake([ GeneralSettings::fake([
'modes' => ['bill'] 'modules' => ['bill']
]); ]);
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
$this->login()->init(); $this->login()->init();
@ -23,7 +23,7 @@ class GlobalSettingTest extends TestCase
$response = $this->get('/setting'); $response = $this->get('/setting');
$response->assertInertiaComponent('setting/Index'); $response->assertInertiaComponent('setting/Index');
$this->assertEquals(['bill'], $response->inertia('general.modes')); $this->assertEquals(['bill'], $response->inertia('general.modules'));
} }
public function testItGetsOptionsForModels(): void public function testItGetsOptionsForModels(): void
@ -33,7 +33,7 @@ class GlobalSettingTest extends TestCase
$response = $this->get('/setting'); $response = $this->get('/setting');
$this->assertContains('bill', $response->inertia('options.modes')); $this->assertContains('bill', $response->inertia('options.modules'));
} }
} }