diff --git a/phpunit.xml b/phpunit.xml index 8aa3a54..4d46992 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,6 @@ - - - - ./src - + + @@ -22,10 +19,13 @@ - - + + + ./src + + diff --git a/src/Modal.php b/src/Modal.php index 8adf331..aecb146 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -10,6 +10,8 @@ use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Routing\Route; use Illuminate\Support\Str; +use Inertia\Support\Header; +use Momentum\Modal\Support\ModalHeader; class Modal implements Responsable { @@ -53,9 +55,9 @@ public function render(): mixed inertia()->share(['modal' => $this->component()]); // render background component on first visit - if (request()->header('X-Inertia') && request()->header('X-Inertia-Partial-Component')) { + if (request()->header(Header::INERTIA) && request()->header(Header::PARTIAL_COMPONENT)) { /** @phpstan-ignore-next-line */ - return inertia()->render(request()->header('X-Inertia-Partial-Component')); + return inertia()->render(request()->header(Header::PARTIAL_COMPONENT)); } /** @var Request $originalRequest */ @@ -108,20 +110,20 @@ protected function component(): array 'baseURL' => $this->baseURL, 'redirectURL' => $this->redirectURL(), 'props' => $this->props, - 'key' => request()->header('X-Inertia-Modal-Key', Str::uuid()->toString()), + 'key' => request()->header(ModalHeader::KEY, Str::uuid()->toString()), 'nonce' => Str::uuid()->toString(), ]; } protected function redirectURL(): string { - if (request()->header('X-Inertia-Modal-Redirect')) { - return request()->header('X-Inertia-Modal-Redirect'); + if (request()->header(ModalHeader::REDIRECT)) { + return request()->header(ModalHeader::REDIRECT); } $referer = request()->headers->get('referer'); - if (request()->header('X-Inertia') && $referer && $referer != url()->current()) { + if (request()->header(Header::INERTIA) && $referer && $referer != url()->current()) { return $referer; } diff --git a/src/Support/ModalHeader.php b/src/Support/ModalHeader.php new file mode 100644 index 0000000..a949ef9 --- /dev/null +++ b/src/Support/ModalHeader.php @@ -0,0 +1,11 @@ +get(route('users.tweets.show', [$user, $tweet]), [ - 'X-Inertia' => true, - 'X-Inertia-Modal-Redirect' => $fromURL, + Header::INERTIA => true, + ModalHeader::REDIRECT => $fromURL, ]) ->assertSuccessful() ->assertJsonPath('component', 'Home') @@ -94,8 +96,8 @@ from($fromURL) ->get(route('users.tweets.show', [$user, $tweet]), [ - 'X-Inertia' => true, - 'X-Inertia-Modal-Redirect' => $fromURL, + Header::INERTIA => true, + ModalHeader::REDIRECT => $fromURL, ]) ->assertJsonPath('component', 'Users/Show') ->assertJsonPath('props.page', '3')