Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions resources/views/components/newsletter-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
{{--
Newsletter signup modal. Opened from anywhere on the site by dispatching an
`open-newsletter-modal` window event, so triggers don't have to be nested
inside it. The form posts straight to Mailcoach, which then redirects to one
of our own `newsletter.*` pages depending on the outcome.
inside it. It also opens itself when the page is loaded with `?newsletter` in
the URL, which is where the `/newsletter` shortlink sends people. The form
posts straight to Mailcoach, which then redirects to one of our own
`newsletter.*` pages depending on the outcome.
--}}
<div
x-data="{ open: false }"
@open-newsletter-modal.window="
open = true
$nextTick(() => $refs.email?.focus())
"
x-data="{
open: false,
show() {
this.open = true
this.$nextTick(() => this.$refs.email?.focus())
},
}"
@if (request()->has('newsletter'))
x-init="show()"
@endif
@open-newsletter-modal.window="show()"
@keydown.escape.window="open = false"
>
{{-- Backdrop --}}
Expand Down
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
|
*/

Route::redirect('newsletter', 'https://simonhamp.mailcoach.app/nativephp');
// The shortlink lands on the homepage and pops the signup modal open.
Route::redirect('newsletter', '/?newsletter=1');
Route::redirect('phpverse-2025', 'https://lp.jetbrains.com/phpverse-2025');
Route::redirect('docs/1/getting-started/sponsoring', '/sponsor');
Route::redirect('docs/desktop/1/getting-started/sponsoring', '/sponsor');
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/NewsletterSignupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ public function the_modal_is_available_on_every_page_of_the_site()
->assertSee(config('services.mailcoach.newsletter_subscribe_url'), escape: false);
}

#[Test]
public function the_newsletter_shortlink_sends_people_to_the_homepage_with_the_modal_open()
{
$this->get('/newsletter')
->assertRedirect('/?newsletter=1');
}

#[Test]
public function the_modal_opens_itself_when_the_url_asks_for_it()
{
$this->get('/?newsletter=1')
->assertOk()
->assertSee('x-init="show()"', escape: false);
}

#[Test]
public function the_modal_stays_closed_on_a_normal_page_load()
{
$this->get('/')
->assertOk()
->assertDontSee('x-init="show()"', escape: false);
}

#[Test]
public function the_confirmation_page_tells_people_to_check_their_inbox()
{
Expand Down