-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Newsletter subscription on checkout success (#60)
- Loading branch information
Showing
7 changed files
with
96 additions
and
33 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
resources/views/checkout/partials/sections/success/newsletter.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<template v-if="$root.loggedIn"> | ||
<x-rapidez-ct::newsletter/> | ||
</template> | ||
@if (Rapidez::config('newsletter/subscription/allow_guest_subscribe', 1)) | ||
<template v-else> | ||
<x-rapidez-ct::newsletter.input email="$root.guestEmail" /> | ||
</template> | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@props(['id' => uniqId('newsletter-')]) | ||
|
||
<x-rapidez-ct::card.inactive> | ||
<x-rapidez-ct::title.lg class="mb-5"> | ||
@lang('Newsletter') | ||
</x-rapidez-ct::title.lg> | ||
|
||
@if (!$attributes->has('v-model')) | ||
<graphql-mutation | ||
v-cloak | ||
query="mutation subscribeNewsletter ($is_subscribed: Boolean!) { updateCustomerV2(input: { is_subscribed: $is_subscribed }) { customer { is_subscribed } } }" | ||
:alert="false" | ||
:clear="false" | ||
:variables="{ is_subscribed: data?.customer?.is_subscribed ?? $root.user?.extension_attributes?.is_subscribed ?? false }" | ||
v-slot="{ mutate, variables }" | ||
> | ||
@endif | ||
|
||
<x-rapidez-ct::newsletter.partials.checkbox | ||
:v-model="$attributes->has('v-model') ? $attributes['v-model'] : 'variables.is_subscribed'" | ||
/> | ||
|
||
@if (!$attributes->has('v-model')) | ||
</graphql-mutation> | ||
@endif | ||
</x-rapidez-ct::card.inactive> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@props(['id' => uniqId('newsletter-'), 'email' => "''"]) | ||
|
||
<x-rapidez-ct::card.inactive class="relative"> | ||
<x-rapidez-ct::title.lg class="mb-5"> | ||
@lang('Newsletter') | ||
</x-rapidez-ct::title.lg> | ||
<x-rapidez-ct::newsletter-visual /> | ||
<graphql-mutation | ||
v-cloak | ||
query="mutation visitor ($email: String!) { subscribeEmailToNewsletter(email: $email) { status } }" | ||
:variables="{ email: {{ $email }} }" | ||
:clear="true" | ||
:notify="{ message: '@lang('Thank you for subscribing')', type: 'success' }" | ||
> | ||
<template slot-scope="{ mutate, variables, mutated, mutating, error }"> | ||
<x-rapidez-ct::newsletter.partials.input /> | ||
</template> | ||
</graphql-mutation> | ||
</x-rapidez-ct::card.inactive> |
14 changes: 14 additions & 0 deletions
14
resources/views/components/newsletter/partials/checkbox.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<x-rapidez-ct::input.checkbox {{ $attributes->merge([ | ||
'class' => 'relative flex w-full cursor-pointer !items-start rounded border bg-white p-7', | ||
'id' => $id, | ||
'v-on:change' => '() => { | ||
if (typeof mutate === \'function\') { mutate() } | ||
if ($root.loggedIn) { $root.user.extension_attributes.is_subscribed=variables.is_subscribed } | ||
}' | ||
]) }}> | ||
<x-slot:slot class="ml-2 flex flex-col gap-1"> | ||
<span class="text-ct-primary text-sm font-medium">@lang('Yes, I want to subscribe to the newsletter')</span> | ||
<span class="text-ct-inactive text-xs font-normal">@lang('You will receive this newsletter approximately 2x a year')</span> | ||
<x-rapidez-ct::newsletter-visual /> | ||
</x-slot:slot> | ||
</x-rapidez-ct::input.checkbox> |
28 changes: 28 additions & 0 deletions
28
resources/views/components/newsletter/partials/input.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<form | ||
class="relative flex gap-3 flex-wrap items-end w-full z-10" | ||
v-on:submit.prevent="mutate" | ||
> | ||
<div class="flex-1"> | ||
<x-rapidez-ct::input | ||
name="email-newsletter" | ||
type="email" | ||
required | ||
v-model="variables.email" | ||
:label="__('Email address')" | ||
:placeholder="__('Enter your email address')" | ||
/> | ||
</div> | ||
<x-rapidez-ct::button.accent | ||
class="relative self-end whitespace-nowrap" | ||
type="submit" | ||
v-bind:disabled="mutating && !error" | ||
> | ||
<div :class="{ 'opacity-0': (mutated || mutating) && !error }"> | ||
@lang('Subscribe to newsletter') | ||
</div> | ||
<div class="absolute inset-0 p-3.5" v-if="(mutated || mutating) && !error"> | ||
<x-heroicon-o-arrow-path class="mx-auto h-full animate-spin" v-if="mutating" /> | ||
<x-heroicon-o-check class="mx-auto h-full" v-else /> | ||
</div> | ||
</x-rapidez-ct::button.accent> | ||
</form> |