fix redirect url after flight creation

This commit is contained in:
Nabeel Shahzad 2026-05-24 23:23:19 -05:00
parent 1fe857c4e3
commit 712b2956d6
No known key found for this signature in database
GPG Key ID: 08C44114D2BF3047
2 changed files with 20 additions and 2 deletions

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Filament\Pages;
use App\Enums\NavigationGroup;
use App\Filament\Resources\FlightBundles\FlightBundleResource;
use App\Models\Airline;
use App\Models\FlightBundle;
use Filament\Pages\Page;
@ -147,11 +148,24 @@ class RouteForge extends Page
*
* The bundle-edit URL is a template `:id` gets substituted client-side
* in CommitSuccessRedirect once the commit response carries bundle_id.
* We derive the path from FlightBundleResource::getUrl() rather than
* hardcoding `/admin/flight-bundles/...` because the resource's `$slug`
* is `flights` (not `flight-bundles`) hardcoding would silently
* redirect to a 404. The sentinel `__RF_BUNDLE_ID__` is alphanumeric so
* Laravel's URL generator leaves it untouched, after which we swap it
* for the `:id` placeholder the TS template expects.
*
* @return array<string, string>
*/
protected function buildRoutesPayload(): array
{
$sentinel = '__RF_BUNDLE_ID__';
$bundleEditTemplate = str_replace(
$sentinel,
':id',
FlightBundleResource::getUrl('edit', ['record' => $sentinel]),
);
return [
'preview_airports' => route('admin.routeforge.api.preview-airports'),
'subfleets' => route('admin.routeforge.api.subfleets'),
@ -159,7 +173,7 @@ class RouteForge extends Page
'check_duplicates' => route('admin.routeforge.api.check-duplicates'),
'lint' => route('admin.routeforge.api.lint'),
'commit' => route('admin.routeforge.api.commit'),
'bundle_edit_template' => '/admin/flight-bundles/:id/edit',
'bundle_edit_template' => $bundleEditTemplate,
];
}

View File

@ -27,10 +27,14 @@ export type CommitSuccessRedirectProps = {
export function CommitSuccessRedirect({ result }: CommitSuccessRedirectProps) {
const template = window.routeforgeConfig?.routes?.bundle_edit_template;
// Fallback path matches FlightBundleResource's actual slug ("flights"),
// not the resource's class name ("FlightBundles"). The backend template
// is derived from FlightBundleResource::getUrl() so this fallback should
// only fire if the config payload is malformed.
const redirectUrl =
template !== undefined && template !== ""
? template.replace(":id", String(result.bundle_id))
: `/admin/flight-bundles/${result.bundle_id}/edit`;
: `/admin/flights/${result.bundle_id}/edit`;
useEffect(() => {
const timer = setTimeout(() => {