From 49afb2e87c52bf2816ae2478b9ffa6a9bffa6db3 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Sat, 12 Sep 2026 01:34:15 +0300 Subject: [PATCH] make template form preview native --- app/javascript/elements/native_action.js | 3 +- app/javascript/form.js | 2 + .../submit_form/_submission_form.html.erb | 2 +- app/views/submit_form/show.html.erb | 14 +++-- .../templates_form_preview/show.html.erb | 58 +++++++++++-------- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/app/javascript/elements/native_action.js b/app/javascript/elements/native_action.js index 2079cdea9..2b8f841e3 100644 --- a/app/javascript/elements/native_action.js +++ b/app/javascript/elements/native_action.js @@ -25,7 +25,8 @@ export default class extends HTMLElement { native: this.dataset.native, url: this.dataset.url, accept: this.dataset.accept, - destructive: this.dataset.destructive === 'true' + destructive: this.dataset.destructive === 'true', + selected: this.dataset.selected === 'true' }) } diff --git a/app/javascript/form.js b/app/javascript/form.js index ab9535caa..54760af75 100644 --- a/app/javascript/form.js +++ b/app/javascript/form.js @@ -8,6 +8,7 @@ import ScrollButtons from './elements/scroll_buttons' import PageContainer from './elements/page_container' import SubmitForm from './elements/submit_form' import ModalButton from './elements/modal_button' +import NativeAction from './elements/native_action' const safeRegisterElement = (name, element, options = {}) => !window.customElements.get(name) && window.customElements.define(name, element, options) @@ -18,6 +19,7 @@ safeRegisterElement('scroll-buttons', ScrollButtons) safeRegisterElement('page-container', PageContainer) safeRegisterElement('submit-form', SubmitForm) safeRegisterElement('modal-button', ModalButton) +safeRegisterElement('native-action', NativeAction) safeRegisterElement('submission-form', class extends HTMLElement { connectedCallback () { this.appElem = document.createElement('div') diff --git a/app/views/submit_form/_submission_form.html.erb b/app/views/submit_form/_submission_form.html.erb index 9dd1b1428..ed3a5723d 100644 --- a/app/views/submit_form/_submission_form.html.erb +++ b/app/views/submit_form/_submission_form.html.erb @@ -2,4 +2,4 @@ <% data_fields = Submissions.filtered_conditions_fields(submitter).to_json %> <% invite_submitters = (submitter.submission.template_submitters || submitter.submission.template.submitters).select { |s| s['invite_by_uuid'] == submitter.uuid && submitter.submission.submitters.none? { |e| e.uuid == s['uuid'] } }.to_json %> <% optional_invite_submitters = (submitter.submission.template_submitters || submitter.submission.template.submitters).select { |s| s['optional_invite_by_uuid'] == submitter.uuid && submitter.submission.submitters.none? { |e| e.uuid == s['uuid'] } }.to_json %> - + diff --git a/app/views/submit_form/show.html.erb b/app/views/submit_form/show.html.erb index 48580c8ff..b90ebd92a 100644 --- a/app/views/submit_form/show.html.erb +++ b/app/views/submit_form/show.html.erb @@ -159,13 +159,15 @@ <% end %> <% end %> - <%= render 'shared/attribution', link_path: '/start', account: @submitter.account, with_style: false %> - <% if @form_configs[:policy_links].present? %> -
-
- <%= MarkdownToHtml.call(@form_configs[:policy_links]) %> + <% unless turbo_native_app? %> + <%= render 'shared/attribution', link_path: '/start', account: @submitter.account, with_style: false %> + <% if @form_configs[:policy_links].present? %> +
+
+ <%= MarkdownToHtml.call(@form_configs[:policy_links]) %> +
-
+ <% end %> <% end %>
diff --git a/app/views/templates_form_preview/show.html.erb b/app/views/templates_form_preview/show.html.erb index c40457cb3..47f1086ee 100644 --- a/app/views/templates_form_preview/show.html.erb +++ b/app/views/templates_form_preview/show.html.erb @@ -1,26 +1,38 @@ -<% banner_html = capture do %> -
-
- <%= @template.name %> -
-
- <% if @template.submitters.size > 1 %> -
- - + <% @template.submitters.each do |submitter| %> + <%= tag.option(value: submitter['uuid'], selected: submitter['uuid'] == @submitter.uuid) do %> + <%= submitter['name'] %> + <% end %> <% end %> - <% end %> - - -
- <% end %> - - <%= t('exit_preview') %> - + + + + <% end %> + + <%= t('exit_preview') %> + +
- + <% end %> <% end %> -<%= render template: 'submit_form/show', locals: { dry_run: true, expand: false, banner_html:, scroll_padding: '-120px' } %> +<%= render template: 'submit_form/show', locals: { dry_run: true, expand: false, banner_html:, scroll_padding: turbo_native_app? ? '-80px' : '-120px' } %>