From: Louis Jeckel Date: Thu, 17 Sep 2020 18:19:53 +0000 (+0200) Subject: create just subscribed notification + subscribe action X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=14d0cc6e376faa5f8ada9a92b30b416f4398a913;p=psq.git create just subscribed notification + subscribe action --- diff --git a/app/Notifications/JustSubscribed.php b/app/Notifications/JustSubscribed.php new file mode 100644 index 0000000..f0a783d --- /dev/null +++ b/app/Notifications/JustSubscribed.php @@ -0,0 +1,75 @@ +subject('PRESCRIPTION SANTÉ QUOTIDIEN : Abonnement activé !') + ->line('Votre abonnement à PRESCRIPTION SANTÉ QUOTIDIEN est désormais actif !') + ->addTag('just-subscribed'); + + + if($notifiable->reg_complete) { + $message->line("Votre compte est déjà activé, vous n'avez rien de plus à faire."); + } else { + $link = $notifiable->routeWithToken('account.index', [], now()->addDays(7)); + $message + ->line("En cliquant sur le bouton ci-dessous vous devez vous créer un mot de passe.") + ->action('Créer mon mot de passe', $link) + ->line("Cela ne prendra pas plus d'une minute !"); + } + + return $message; + + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/app/Nova/Actions/SendNotification.php b/app/Nova/Actions/SendNotification.php index 404616d..8155480 100644 --- a/app/Nova/Actions/SendNotification.php +++ b/app/Nova/Actions/SendNotification.php @@ -47,8 +47,9 @@ class SendNotification extends Action { return [ Select::make('Notification')->options([ - Notifications\Welcome::class => 'Message de bienvenue', +// Notifications\Welcome::class => 'Message de bienvenue', Notifications\RegistrationPending::class => 'Rappel', + Notifications\JustSubscribed::class => 'Message abonnement activé' ]) ]; } diff --git a/app/Nova/Actions/SubscribeUser.php b/app/Nova/Actions/SubscribeUser.php new file mode 100644 index 0000000..215fd25 --- /dev/null +++ b/app/Nova/Actions/SubscribeUser.php @@ -0,0 +1,67 @@ +filter(fn($user) => $user->type !== User::TYPE_SUBSCRIBER); + + $users->map(function(User $user) use($fields) { + + $user->type = User::TYPE_SUBSCRIBER; + $user->organization()->associate(\App\Organization::query()->findOrFail($fields->org_id)); + $user->save(); + if(! $fields->dont_notify) { + $user->notify(new JustSubscribed); + } + }); + + return Action::message(count($users). " abonnements activés !"); + } + + /** + * Get the fields available on the action. + * + * @return array + */ + public function fields() + { + return [ + Select::make('Organisation', 'org_id')->options( + \App\Organization::query() + ->orderBy('name') + ->where('subscription_active', 1) + ->get() + ->pluck('name', 'id') + + )->searchable(), + Boolean::make("Ne pas notifier", 'dont_notify') + ]; + } +} diff --git a/app/Nova/DiscoverUsers.php b/app/Nova/DiscoverUsers.php index 120a749..0417230 100644 --- a/app/Nova/DiscoverUsers.php +++ b/app/Nova/DiscoverUsers.php @@ -4,9 +4,11 @@ namespace App\Nova; +use App\Nova\Actions\SubscribeUser; use Carbon\Carbon; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\Text; +use Illuminate\Http\Request; use Laravel\Nova\Http\Requests\NovaRequest; class DiscoverUsers extends User @@ -40,5 +42,11 @@ class DiscoverUsers extends User ]; } + public function actions(Request $request) + { + return array_merge(parent::actions($request), [ + new SubscribeUser, + ]); + } } diff --git a/app/Nova/Prospect.php b/app/Nova/Prospect.php index 3a3a655..2669179 100644 --- a/app/Nova/Prospect.php +++ b/app/Nova/Prospect.php @@ -4,6 +4,8 @@ namespace App\Nova; +use App\Nova\Actions\SubscribeUser; +use Illuminate\Http\Request; use Laravel\Nova\Http\Requests\NovaRequest; class Prospect extends User @@ -23,4 +25,11 @@ class Prospect extends User return "Prospect"; } + public function actions(Request $request) + { + return array_merge(parent::actions($request), [ + new SubscribeUser, + ]); + } + }