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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
dabef40
Form Focused mode - WIP
chiragchhatrala Dec 4, 2024
72264ae
Implement focused form mode in OpenCompleteForm and add OpenFormFocus…
chiragchhatrala Dec 5, 2024
440125a
Enhance OpenForm components for improved navigation and visual consis…
chiragchhatrala Dec 5, 2024
b1febab
Add FormatChangeModal component and integrate format change handling …
chiragchhatrala Dec 9, 2024
a791916
Enhance OpenFormFocused and FieldOptions components for improved user…
chiragchhatrala Dec 9, 2024
62d86f3
Merge branch 'main' into 147a6-form-focused-mode
chiragchhatrala Dec 9, 2024
a1ad9fd
Update OpenFormFocused component and add internationalization support…
chiragchhatrala Dec 10, 2024
61143fc
Refactor OpenFormFocused component to streamline field handling and i…
chiragchhatrala Dec 10, 2024
9a19502
When form is focused mode make cover image screen
chiragchhatrala Dec 10, 2024
459dcf7
Merge branch 'main' into 147a6-form-focused-mode
chiragchhatrala Dec 10, 2024
0db1fc0
Add translations for 'Back' and 'Next' buttons in new languages
chiragchhatrala Dec 10, 2024
f24cab9
Enhance form components by adding 'creating' prop for improved state …
chiragchhatrala Dec 10, 2024
cd60d43
Update form components and dependencies
JhumanJ Dec 18, 2024
1b93185
Merge branch 'main' into 147a6-form-focused-mode
JhumanJ Jan 3, 2025
228df27
Merge branch '147a6-form-focused-mode' of https://github.com/JhumanJ/…
JhumanJ Jan 3, 2025
838bf34
Merge branch 'main' into 147a6-form-focused-mode
JhumanJ Jan 31, 2025
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'];

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>
29 changes: 27 additions & 2 deletions client/components/open/forms/OpenCompleteForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
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"
Expand All @@ -130,6 +130,29 @@
</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"
@submit="submitForm"
>
<template #submit-btn="{submitForm}">
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix variable shadowing in submit button template.

The submitForm parameter shadows the method from the parent scope. Rename it to avoid confusion.

-<template #submit-btn="{submitForm}">
+<template #submit-btn="{submitForm: handleFocusedSubmit}">
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<template #submit-btn="{submitForm}">
<template #submit-btn="{submitForm: handleFocusedSubmit}">
🧰 Tools
🪛 GitHub Check: Run client linters

[warning] 161-161:
Variable 'submitForm' is already declared in the upper scope

🪛 GitHub Actions: laravel

[warning] 161-161: Variable 'submitForm' is already declared in the upper scope

<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 +225,8 @@
<script>
import OpenForm from './OpenForm.vue'
import OpenFormButton from './OpenFormButton.vue'
import OpenFormFocused from './OpenFormFocused.vue'
import FormTimer from './FormTimer.vue'
Comment on lines +246 to +247
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused FormTimer component.

The FormTimer component is imported and registered but not used in the template.

-import FormTimer from './FormTimer.vue'
 import FormCleanings from '../../pages/forms/show/FormCleanings.vue'
 
 export default {
-  components: { VTransition, OpenFormButton, OpenForm, OpenFormFocused, FormCleanings, FormTimer, FirstSubmissionModal },
+  components: { VTransition, OpenFormButton, OpenForm, OpenFormFocused, FormCleanings, FirstSubmissionModal },

Also applies to: 256-256

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 +235,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
1 change: 1 addition & 0 deletions client/components/open/forms/OpenForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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
Loading