Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form focused mode #640

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions api/app/Http/Requests/UserFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function rules()
'visibility' => ['required', Rule::in(Form::VISIBILITY)],

// Customization
'format' => ['required', Rule::in(Form::FORMATS)],
'language' => ['required', Rule::in(Form::LANGUAGES)],
'font_family' => 'string|nullable',
'theme' => ['required', Rule::in(Form::THEMES)],
Expand Down
3 changes: 3 additions & 0 deletions api/app/Models/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Form extends Model implements CachableAttributes

public const VISIBILITY = ['public', 'draft', 'closed'];

public const FORMATS = ['regular', 'focused'];

public const LANGUAGES = ['en', 'fr', 'hi', 'es', 'ar', 'zh', 'ja', 'bn', 'pt', 'ru', 'ur', 'pa', 'de', 'jv', 'ko', 'vi', 'te', 'mr', 'ta', 'tr'];

protected $fillable = [
Expand All @@ -54,6 +56,7 @@ class Form extends Model implements CachableAttributes
'visibility',

// Customization
'format',
'language',
'font_family',
'custom_domain',
Expand Down
1 change: 1 addition & 0 deletions api/database/factories/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function definition()
'title' => $this->faker->text(30),
'description' => $this->faker->randomHtml(1),
'visibility' => 'public',
'format' => 'regular',
'language' => 'en',
'theme' => $this->faker->randomElement(Form::THEMES),
'size' => $this->faker->randomElement(Form::SIZES),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->string('format')->default('regular');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('format');
});
}
};
75 changes: 75 additions & 0 deletions client/components/open/editors/FormatChangeModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<modal
:show="show && form.format === 'focused' && removeBlocks.length > 0"
:compact-header="true"
:closeable="false"
@close="onCancel"
>
<template #icon>
<Icon
name="heroicons:document-text"
class="w-10 h-10 text-blue"
/>
</template>
<template #title>
Format Change
</template>

<div class="p-4">
If you change the format, below block(s) will be removed from the form:
<ul
v-if="removeBlocks.length > 0"
class="list-disc ml-4 mt-2"
>
<li
v-for="block in removeBlocks"
:key="block.id"
>
{{ block.name }}
</li>
</ul>

<div class="flex justify-end mt-4 px-6">
<v-button
class="mr-2"
@click.prevent="changeFormat"
>
It's ok
</v-button>
<v-button
color="white"
@click.prevent="onCancel"
>
Cancel
</v-button>
</div>
</div>
</modal>
</template>

<script setup>
const props = defineProps({
show: {
type: Boolean,
default: false,
}
})

const emit = defineEmits(['close'])
const removeTypes = ['nf-page-break','nf-divider','nf-image','nf-code']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Move removeTypes to a constants file

The removeTypes array should be moved to a constants file for better maintainability and reusability.

Create a new constant in a shared location:

-const removeTypes = ['nf-page-break','nf-divider','nf-image','nf-code']
+import { REMOVABLE_BLOCK_TYPES } from '@/constants/forms'
+const removeTypes = REMOVABLE_BLOCK_TYPES

Committable suggestion skipped: line range outside the PR's diff.

const formStore = useWorkingFormStore()
const form = computed(() => formStore.content)

const removeBlocks = computed(() => form.value.properties.filter(field => removeTypes.includes(field.type)))

const changeFormat = () => {
form.value.properties = form.value.properties.filter(property => !removeTypes.includes(property.type))
form.value.format = 'focused'
emit('close')
}

const onCancel = () => {
form.value.format = 'regular'
emit('close')
}
</script>
31 changes: 29 additions & 2 deletions client/components/open/forms/OpenCompleteForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@
key="form"
>
<open-form
v-if="form && !form.is_closed"
v-if="form && !form.is_closed && form.format === 'regular'"
:form="form"
:loading="loading"
:fields="form.properties"
:theme="theme"
:dark-mode="darkMode"
:admin-preview="adminPreview"
:creating="creating"
@submit="submitForm"
>
<template #submit-btn="{submitForm}">
Expand All @@ -130,6 +131,30 @@
</open-form-button>
</template>
</open-form>
<open-form-focused
v-else-if="form && !form.is_closed && form.format === 'focused'"
:form="form"
:loading="loading"
:fields="form.properties"
:theme="theme"
:dark-mode="darkMode"
:admin-preview="adminPreview"
:creating="creating"
@submit="submitForm"
>
<template #submit-btn="{submitForm}">
<open-form-button
:loading="loading"
:theme="theme"
:color="form.color"
class="mt-2 px-8 mx-1"
:class="submitButtonClass"
@click.prevent="submitForm"
>
{{ form.submit_button_text }}
</open-form-button>
</template>
</open-form-focused>
<p
v-if="!form.no_branding"
class="text-center w-full mt-2"
Expand Down Expand Up @@ -202,6 +227,8 @@
<script>
import OpenForm from './OpenForm.vue'
import OpenFormButton from './OpenFormButton.vue'
import OpenFormFocused from './OpenFormFocused.vue'
import FormTimer from './FormTimer.vue'
import FormCleanings from '../../pages/forms/show/FormCleanings.vue'
import VTransition from '~/components/global/transitions/VTransition.vue'
import {pendingSubmission} from "~/composables/forms/pendingSubmission.js"
Expand All @@ -210,7 +237,7 @@ import ThemeBuilder from "~/lib/forms/themes/ThemeBuilder.js"
import FirstSubmissionModal from '~/components/open/forms/components/FirstSubmissionModal.vue'

export default {
components: { VTransition, OpenFormButton, OpenForm, FormCleanings, FirstSubmissionModal },
components: { VTransition, OpenFormButton, OpenForm, OpenFormFocused, FormCleanings, FormTimer, FirstSubmissionModal },

props: {
form: { type: Object, required: true },
Expand Down
4 changes: 3 additions & 1 deletion client/components/open/forms/OpenForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default {
required: true
},
defaultDataForm: { type: [Object, null] },
creating: {type: Boolean, default: false},
adminPreview: {type: Boolean, default: false}, // If used in FormEditorPreview
urlPrefillPreview: {type: Boolean, default: false}, // If used in UrlFormPrefill
darkMode: {
Expand Down Expand Up @@ -275,6 +276,7 @@ export default {
previousFieldsPageBreak() {
if (this.formPageIndex === 0) return null
const previousFields = this.fieldGroups[this.formPageIndex - 1]
if (!previousFields?.length) return null
const block = previousFields[previousFields.length - 1]
if (block && block.type === 'nf-page-break') return block
return null
Expand Down Expand Up @@ -527,7 +529,7 @@ export default {
this.scrollToTop()
},
nextPage() {
if (this.adminPreview || this.urlPrefillPreview) {
if (this.adminPreview || this.urlPrefillPreview || this.creating) {
this.formPageIndex++
this.scrollToTop()
return false
Expand Down
Loading
Loading