feat(120): alert component unification

Phase 120 - Plan 01:
- Reusable PHP alert component (resources/views/components/alert.php)
  with inline SVG icon per type, optional dismiss button.
- Missing .alert--info SCSS variant added (#eff6ff/#bfdbfe/#1e3a8a) -
  fixes black-on-white alert after Fakturownia test connection.
- Flash::push(type, message) + Flash::all() with BC for set/get;
  legacy key heuristic (error/.save/warning -> typed entries).
- Central flash renderer in 3 layouts (app/auth/public) iterating
  Flash::all() through component (.alerts-stack wrap).
- Vanilla JS alert-dismiss.js with idempotent guard and delegated
  click handler on [data-alert-dismiss].
- 36 views migrated off inline <div class="alert alert--TYPE">;
  .flash--error/success removed from views (orders/show, shipments/prepare).
- SCSS rebuilt: public/assets/css/{app,login}.css.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 18:47:41 +02:00
parent 3a2c419c25
commit 933dfcc67b
51 changed files with 1109 additions and 210 deletions

View File

@@ -1,103 +1,115 @@
<?php
/** @var array<int, array<string, mixed>> $rows */
$rows = is_array($rows ?? null) ? $rows : [];
/** @var array<string, mixed> $settings */
$settings = is_array($settings ?? null) ? $settings : [];
$integrationId = (int) ($settings['integration_id'] ?? 0);
$prefix = (string) ($settings['account_prefix'] ?? '');
$departmentId = (string) ($settings['department_id'] ?? '');
$defaultKind = (string) ($settings['default_kind'] ?? 'vat');
$defaultPaymentDays = (int) ($settings['default_payment_to_days'] ?? 7);
$isActive = (bool) ($settings['is_active'] ?? true);
$hasToken = (bool) ($settings['has_api_token'] ?? false);
$lastTestAt = (string) ($settings['last_test_at'] ?? '');
$lastTestStatus = (string) ($settings['last_test_status'] ?? '');
$lastTestMessage = (string) ($settings['last_test_message'] ?? '');
$flashSave = trim((string) ($flashSave ?? ''));
$flashTest = trim((string) ($flashTest ?? ''));
$flashError = trim((string) ($flashError ?? ''));
?>
<section class="card">
<h2 class="section-title">Integracje Fakturownia</h2>
<p class="muted mt-12">Konfiguracja kont Fakturowni do wystawiania faktur dla zamowien.</p>
<h2 class="section-title">Integracja Fakturownia</h2>
<p class="muted mt-12">Jedna globalna konfiguracja konta Fakturowni do wystawiania faktur delegowanych.</p>
<?php if ($flashError !== ''): ?>
<div class="alert alert--danger mt-12" role="alert"><?= $e($flashError) ?></div>
<div class="mt-12"><?php $type='danger'; $message=$flashError; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
<?php endif; ?>
<?php if ($flashSave !== ''): ?>
<div class="alert alert--success mt-12" role="status"><?= $e($flashSave) ?></div>
<div class="mt-12"><?php $type='success'; $message=$flashSave; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
<?php endif; ?>
<?php if ($flashTest !== ''): ?>
<div class="alert alert--info mt-12" role="status"><?= $e($flashTest) ?></div>
<div class="mt-12"><?php $type='info'; $message=$flashTest; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
<?php endif; ?>
</section>
<section class="card mt-16">
<h3 class="section-title">Lista integracji</h3>
<div class="form-actions mt-12">
<a class="btn btn--primary" href="/settings/integrations/fakturownia/new">Dodaj integracje</a>
<h3 class="section-title">Konfiguracja</h3>
<div class="muted mt-12">
Token:
<strong><?= $e($hasToken ? 'zapisany' : 'brak') ?></strong>
&nbsp; Status:
<strong><?= $e($isActive ? 'aktywna' : 'nieaktywna') ?></strong>
</div>
<?php if ($rows === []): ?>
<p class="muted mt-12">Brak skonfigurowanych integracji Fakturowni. Dodaj pierwsza ponizej.</p>
<?php else: ?>
<div class="table-wrap mt-12">
<table class="table">
<thead>
<tr>
<th>Nazwa</th>
<th>Subdomena</th>
<th>Token</th>
<th>Status</th>
<th>Ostatni test</th>
<th>Akcje</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row):
$integrationId = (int) ($row['integration_id'] ?? 0);
$name = (string) ($row['name'] ?? '');
$prefix = (string) ($row['account_prefix'] ?? '');
$hasToken = (bool) ($row['has_api_token'] ?? false);
$isActive = (bool) ($row['is_active'] ?? false);
$lastTestAt = (string) ($row['last_test_at'] ?? '');
$lastTestStatus = (string) ($row['last_test_status'] ?? '');
?>
<tr>
<td><?= $e($name) ?></td>
<td>
<?php if ($prefix !== ''): ?>
<?= $e($prefix . '.fakturownia.pl') ?>
<?php else: ?>
<span class="muted">brak</span>
<?php endif; ?>
</td>
<td>
<?php if ($hasToken): ?>
<span class="badge badge--success">Zapisany</span>
<?php else: ?>
<span class="badge badge--muted">Brak</span>
<?php endif; ?>
</td>
<td>
<?php if ($isActive): ?>
<span class="badge badge--success">Aktywna</span>
<?php else: ?>
<span class="badge badge--muted">Nieaktywna</span>
<?php endif; ?>
</td>
<td>
<?php if ($lastTestAt !== ''): ?>
<?= $e($lastTestAt) ?>
<?php if ($lastTestStatus !== ''): ?>
<span class="badge badge--<?= $lastTestStatus === 'ok' ? 'success' : 'muted' ?>"><?= $e(strtoupper($lastTestStatus)) ?></span>
<?php endif; ?>
<?php else: ?>
<span class="muted">nigdy</span>
<?php endif; ?>
</td>
<td style="white-space:nowrap">
<a href="/settings/integrations/fakturownia/edit?id=<?= $integrationId ?>" class="btn btn--sm btn--secondary">Edytuj</a>
<form action="/settings/integrations/fakturownia/delete" method="post" style="display:inline" class="js-confirm-delete">
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
<input type="hidden" name="id" value="<?= $integrationId ?>">
<button type="button" class="btn btn--sm btn--danger js-delete-btn">Usun</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<form class="statuses-form mt-16" action="/settings/integrations/fakturownia/save" method="post" novalidate>
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
<label class="form-field">
<span class="field-label">Prefix konta (subdomena) *</span>
<input class="form-control" type="text" name="account_prefix" maxlength="63" value="<?= $e($prefix) ?>" pattern="[a-z0-9][a-z0-9-]{1,62}" required>
<span class="muted">Wpisz sama subdomene, bez koncowki .fakturownia.pl.</span>
</label>
<label class="form-field">
<span class="field-label">Token API <?= $hasToken ? '' : '*' ?></span>
<input class="form-control" type="password" name="api_token" autocomplete="new-password" placeholder="<?= $hasToken ? '********' : '' ?>" <?= $hasToken ? '' : 'required' ?>>
<span class="muted"><?= $hasToken ? 'Token jest zapisany. Wpisz nowy, aby go nadpisac.' : 'Token API z Fakturowni (Ustawienia > Konta uzytkownikow > API).' ?></span>
</label>
<label class="form-field">
<span class="field-label">ID departamentu (opcjonalnie)</span>
<input class="form-control" type="text" name="department_id" maxlength="64" value="<?= $e($departmentId) ?>">
</label>
<div class="form-grid-2 mt-0">
<label class="form-field">
<span class="field-label">Domyslny typ dokumentu</span>
<select class="form-control" name="default_kind">
<option value="vat" <?= $defaultKind === 'vat' ? 'selected' : '' ?>>Faktura VAT</option>
<option value="proforma" <?= $defaultKind === 'proforma' ? 'selected' : '' ?>>Proforma</option>
<option value="invoice_other" <?= $defaultKind === 'invoice_other' ? 'selected' : '' ?>>Inna</option>
</select>
</label>
<label class="form-field">
<span class="field-label">Domyslny termin platnosci (dni)</span>
<input class="form-control" type="number" name="default_payment_to_days" min="0" max="120" value="<?= $defaultPaymentDays ?>">
</label>
</div>
<label class="form-field">
<span class="field-label">Status</span>
<label>
<input type="checkbox" name="is_active" value="1" <?= $isActive ? 'checked' : '' ?>>
Integracja aktywna
</label>
</label>
<div class="form-actions">
<button type="submit" class="btn btn--primary">Zapisz</button>
</div>
</form>
</section>
<section class="card mt-16">
<h3 class="section-title">Test polaczenia</h3>
<p class="muted mt-12">Wykonuje GET <code><?= $e('https://' . ($prefix !== '' ? $prefix : '{prefix}') . '.fakturownia.pl/account.json') ?></code> z zapisanym tokenem.</p>
<form action="/settings/integrations/fakturownia/test" method="post" class="mt-12">
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
<input type="hidden" name="id" value="<?= $integrationId ?>">
<button type="submit" class="btn btn--secondary">Testuj polaczenie</button>
</form>
<?php if ($lastTestAt !== ''): ?>
<div class="muted mt-12">
Ostatni test: <strong><?= $e($lastTestAt) ?></strong>
<?php if ($lastTestStatus !== ''): ?>
<span class="badge badge--<?= $lastTestStatus === 'ok' ? 'success' : 'muted' ?>"><?= $e(strtoupper($lastTestStatus)) ?></span>
<?php endif; ?>
<?php if ($lastTestMessage !== ''): ?>
<div><?= $e($lastTestMessage) ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
</section>