Skip to content

Commit 20405ee

Browse files
Send mobile editor email (#634)
Co-authored-by: Julien Nahum <julien@nahum.net>
1 parent ea4cd85 commit 20405ee

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

api/app/Http/Controllers/Forms/FormController.php

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Http\Resources\FormResource;
1010
use App\Models\Forms\Form;
1111
use App\Models\Workspace;
12+
use App\Notifications\Forms\MobileEditorEmail;
1213
use App\Service\Forms\FormCleaner;
1314
use App\Service\Storage\StorageFileNameParser;
1415
use Illuminate\Support\Facades\Auth;
@@ -271,4 +272,16 @@ public function updateWorkspace($id, $workspace_id)
271272
'message' => 'Form workspace updated successfully.',
272273
]);
273274
}
275+
276+
public function mobileEditorEmail($id)
277+
{
278+
$form = Form::findOrFail($id);
279+
$this->authorize('update', $form);
280+
281+
$form->creator->notify(new MobileEditorEmail($form->slug));
282+
283+
return $this->success([
284+
'message' => 'Email sent.',
285+
]);
286+
}
274287
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Notifications\Forms;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Messages\MailMessage;
8+
use Illuminate\Notifications\Notification;
9+
10+
class MobileEditorEmail extends Notification implements ShouldQueue
11+
{
12+
use Queueable;
13+
14+
protected $slug;
15+
16+
/**
17+
* Create a new notification instance.
18+
*
19+
* @param string $slug
20+
* @return void
21+
*/
22+
public function __construct($slug)
23+
{
24+
$this->slug = $slug;
25+
}
26+
27+
/**
28+
* Get the notification's delivery channels.
29+
*
30+
* @param mixed $notifiable
31+
* @return array
32+
*/
33+
public function via($notifiable)
34+
{
35+
return ['mail'];
36+
}
37+
38+
/**
39+
* Get the mail representation of the notification.
40+
*
41+
* @param mixed $notifiable
42+
* @return \Illuminate\Notifications\Messages\MailMessage
43+
*/
44+
public function toMail($notifiable)
45+
{
46+
return (new MailMessage())
47+
->subject('Continue editing your form on desktop')
48+
->line('We noticed you\'re editing a form on smaller screen.')
49+
->line('For the best form building experience, we recommend using a desktop computer.')
50+
->line('Ready to create something amazing? Click below to continue editing. 💻')
51+
->action(__('Continue Editing'), front_url('forms/' . $this->slug . '/edit'));
52+
}
53+
}

api/routes/api.php

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
Route::post('/{id}/workspace/{workspace_id}', [FormController::class, 'updateWorkspace'])->name('workspace.update');
158158
Route::put('/{id}', [FormController::class, 'update'])->name('update');
159159
Route::delete('/{id}', [FormController::class, 'destroy'])->name('destroy');
160+
Route::get('/{id}/mobile-editor-email', [FormController::class, 'mobileEditorEmail'])->name('mobile-editor-email');
160161

161162
Route::get('/{id}/submissions', [FormSubmissionController::class, 'submissions'])->name('submissions');
162163
Route::put('/{id}/submissions/{submission_id}', [FormSubmissionController::class, 'update'])->name('submissions.update')->middleware([ResolveFormMiddleware::class]);

client/components/open/forms/components/FormEditor.vue

+11
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import { captureException } from "@sentry/core"
106106
import FormSettings from './form-components/FormSettings.vue'
107107
import FormEditorErrorHandler from '~/components/open/forms/components/FormEditorErrorHandler.vue'
108108
import { setFormDefaults } from '~/composables/forms/initForm.js'
109+
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
109110
110111
export default {
111112
name: "FormEditor",
@@ -145,6 +146,16 @@ export default {
145146
emits: ['mounted', 'on-save', 'openRegister', 'go-back', 'save-form'],
146147
147148
setup() {
149+
// Check if the editor is visible on smaller screens then send an email
150+
const breakpoints = useBreakpoints(breakpointsTailwind)
151+
const isVisible = ref(breakpoints.smaller("md"))
152+
watch(isVisible, (newValue) => {
153+
if (newValue) {
154+
opnFetch('/open/forms/' + form.value.id + '/mobile-editor-email')
155+
}
156+
})
157+
158+
148159
const { user } = storeToRefs(useAuthStore())
149160
const formsStore = useFormsStore()
150161
const { content: form } = storeToRefs(useWorkingFormStore())

0 commit comments

Comments
 (0)