allow to invite party
This commit is contained in:
committed by
Oleksandr Turchyn
parent
3604fb6461
commit
10fbdf6612
@@ -68,6 +68,9 @@ RSpec/ExampleLength:
|
||||
RSpec/MultipleMemoizedHelpers:
|
||||
Max: 6
|
||||
|
||||
Metrics/BlockNesting:
|
||||
Max: 4
|
||||
|
||||
Rails/I18nLocaleTexts:
|
||||
Enabled: false
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ module Api
|
||||
:name,
|
||||
:external_id,
|
||||
{
|
||||
submitters: [%i[name uuid is_requester linked_to_uuid email]],
|
||||
submitters: [%i[name uuid is_requester invite_by_uuid invite_by_uuid linked_to_uuid email]],
|
||||
fields: [[:uuid, :submitter_uuid, :name, :type,
|
||||
:required, :readonly, :default_value,
|
||||
:title, :description,
|
||||
|
||||
@@ -23,7 +23,7 @@ class StartFormController < ApplicationController
|
||||
if @submitter.completed_at?
|
||||
redirect_to start_form_completed_path(@template.slug, email: submitter_params[:email])
|
||||
else
|
||||
if filter_undefined_submitters(@template).size > 2 && @submitter.new_record?
|
||||
if filter_undefined_submitters(@template).size > 1 && @submitter.new_record?
|
||||
@error_message = 'Not found'
|
||||
|
||||
return render :show
|
||||
@@ -95,9 +95,7 @@ class StartFormController < ApplicationController
|
||||
end
|
||||
|
||||
def filter_undefined_submitters(template)
|
||||
template.submitters.select do |item|
|
||||
item['linked_to_uuid'].blank? && item['is_requester'].blank? && item['email'].blank?
|
||||
end
|
||||
Templates.filter_undefined_submitters(template)
|
||||
end
|
||||
|
||||
def submitter_params
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubmitFormInviteController < ApplicationController
|
||||
skip_before_action :authenticate_user!
|
||||
skip_authorization_check
|
||||
|
||||
def create
|
||||
submitter = Submitter.find_by!(slug: params[:submit_form_slug])
|
||||
|
||||
return head :unprocessable_entity unless can_invite?(submitter)
|
||||
|
||||
invite_submitters = filter_invite_submitters(submitter)
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
invite_submitters.each do |item|
|
||||
attrs = submitters_attributes.find { |e| e[:uuid] == item['uuid'] }
|
||||
|
||||
next unless attrs
|
||||
|
||||
submitter.submission.submitters.create!(**attrs, account_id: submitter.account_id)
|
||||
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'invite_party', request, { uuid: submitter.uuid })
|
||||
end
|
||||
|
||||
submitter.submission.update!(submitters_order: :preserved)
|
||||
end
|
||||
|
||||
submitter.submission.submitters.reload
|
||||
|
||||
if invite_submitters.all? { |s| submitter.submission.submitters.any? { |e| e.uuid == s['uuid'] } }
|
||||
Submitters::SubmitValues.call(submitter, ActionController::Parameters.new(completed: 'true'), request)
|
||||
|
||||
head :ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def can_invite?(submitter)
|
||||
!submitter.declined_at? &&
|
||||
!submitter.completed_at? &&
|
||||
!submitter.submission.archived_at? &&
|
||||
!submitter.submission.expired? &&
|
||||
!submitter.submission.template.archived_at?
|
||||
end
|
||||
|
||||
def filter_invite_submitters(submitter)
|
||||
(submitter.submission.template_submitters || submitter.submission.template.submitters).select do |s|
|
||||
s['invite_by_uuid'] == submitter.uuid && submitter.submission.submitters.none? { |e| e.uuid == s['uuid'] }
|
||||
end
|
||||
end
|
||||
|
||||
def submitters_attributes
|
||||
params.require(:submission).permit(submitters: [%i[uuid email]]).fetch(:submitters, [])
|
||||
end
|
||||
end
|
||||
@@ -103,7 +103,7 @@ class TemplatesController < ApplicationController
|
||||
params.require(:template).permit(
|
||||
:name,
|
||||
{ schema: [%i[attachment_uuid name]],
|
||||
submitters: [%i[name uuid is_requester linked_to_uuid email]],
|
||||
submitters: [%i[name uuid is_requester linked_to_uuid invite_by_uuid email]],
|
||||
fields: [[:uuid, :submitter_uuid, :name, :type,
|
||||
:required, :readonly, :default_value,
|
||||
:title, :description,
|
||||
|
||||
@@ -18,16 +18,18 @@ class TemplatesRecipientsController < ApplicationController
|
||||
|
||||
def submitters_params
|
||||
params.require(:template).permit(
|
||||
submitters: [%i[name uuid is_requester linked_to_uuid email option]]
|
||||
submitters: [%i[name uuid is_requester invite_by_uuid linked_to_uuid email option]]
|
||||
).fetch(:submitters, {}).values.filter_map do |s|
|
||||
next if s[:uuid].blank?
|
||||
|
||||
if s[:is_requester] == '1'
|
||||
if s[:is_requester] == '1' && s[:invite_by_uuid].blank?
|
||||
s[:is_requester] = true
|
||||
else
|
||||
s.delete(:is_requester)
|
||||
end
|
||||
|
||||
s.delete(:invite_by_uuid) if s[:invite_by_uuid].blank?
|
||||
|
||||
option = s.delete(:option)
|
||||
|
||||
if option.present?
|
||||
@@ -38,8 +40,11 @@ class TemplatesRecipientsController < ApplicationController
|
||||
s.delete(:is_requester)
|
||||
s.delete(:email)
|
||||
s.delete(:linked_to_uuid)
|
||||
s.delete(:invite_by_uuid)
|
||||
when /\Alinked_to_(.*)\z/
|
||||
s[:linked_to_uuid] = ::Regexp.last_match(-1)
|
||||
when /\Ainvite_by_(.*)\z/
|
||||
s[:invite_by_uuid] = ::Regexp.last_match(-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import PasswordInput from './elements/password_input'
|
||||
import SearchInput from './elements/search_input'
|
||||
import ToggleAttribute from './elements/toggle_attribute'
|
||||
import LinkedInput from './elements/linked_input'
|
||||
import CheckboxGroup from './elements/checkbox_group'
|
||||
|
||||
import * as TurboInstantClick from './lib/turbo_instant_click'
|
||||
|
||||
@@ -93,6 +94,7 @@ safeRegisterElement('password-input', PasswordInput)
|
||||
safeRegisterElement('search-input', SearchInput)
|
||||
safeRegisterElement('toggle-attribute', ToggleAttribute)
|
||||
safeRegisterElement('linked-input', LinkedInput)
|
||||
safeRegisterElement('checkbox-group', CheckboxGroup)
|
||||
|
||||
safeRegisterElement('template-builder', class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export default class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
this.items.forEach((item) => {
|
||||
item.addEventListener('change', (e) => {
|
||||
this.items.forEach((item) => {
|
||||
item.checked = item === e.target && e.target.checked
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
get items () {
|
||||
return this.querySelectorAll('input[type="checkbox"]')
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ safeRegisterElement('submission-form', class extends HTMLElement {
|
||||
|
||||
this.app = createApp(Form, {
|
||||
submitter: JSON.parse(this.dataset.submitter),
|
||||
inviteSubmitters: JSON.parse(this.dataset.inviteSubmitters),
|
||||
canSendEmail: this.dataset.canSendEmail === 'true',
|
||||
previousSignatureValue: this.dataset.previousSignatureValue,
|
||||
goToLast: this.dataset.goToLast === 'true',
|
||||
|
||||
@@ -436,6 +436,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<InviteForm
|
||||
v-else-if="!isInvited && inviteSubmitters.length"
|
||||
:submitters="inviteSubmitters"
|
||||
:submitter-slug="submitterSlug"
|
||||
:authenticity-token="authenticityToken"
|
||||
:url="baseUrl + submitPath + '/invite'"
|
||||
:style="{ maxWidth: isBreakpointMd ? '582px' : '' }"
|
||||
@success="isInvited = true"
|
||||
/>
|
||||
<FormCompleted
|
||||
v-else
|
||||
:is-demo="isDemo"
|
||||
@@ -485,6 +494,7 @@ import TextStep from './text_step'
|
||||
import NumberStep from './number_step'
|
||||
import DateStep from './date_step'
|
||||
import MarkdownContent from './markdown_content'
|
||||
import InviteForm from './invite_form'
|
||||
import FormCompleted from './completed'
|
||||
import { IconInnerShadowTop, IconArrowsDiagonal, IconWritingSign, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue'
|
||||
import AppearsOn from './appears_on'
|
||||
@@ -522,6 +532,7 @@ export default {
|
||||
IconWritingSign,
|
||||
AttachmentStep,
|
||||
InitialsStep,
|
||||
InviteForm,
|
||||
MultiSelectStep,
|
||||
IconInnerShadowTop,
|
||||
DateStep,
|
||||
@@ -548,6 +559,11 @@ export default {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
inviteSubmitters: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => []
|
||||
},
|
||||
withSignatureId: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
@@ -739,6 +755,7 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
isCompleted: false,
|
||||
isInvited: false,
|
||||
isFormVisible: this.expand !== false,
|
||||
showFillAllRequiredFields: false,
|
||||
currentStep: 0,
|
||||
@@ -1119,7 +1136,7 @@ export default {
|
||||
const formData = new FormData(this.$refs.form)
|
||||
const isLastStep = this.currentStep === this.stepFields.length - 1
|
||||
|
||||
if (isLastStep && !emptyRequiredField) {
|
||||
if (isLastStep && !emptyRequiredField && !this.inviteSubmitters.length) {
|
||||
formData.append('completed', 'true')
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ const en = {
|
||||
reviewed: 'Reviewed',
|
||||
other: 'Other',
|
||||
authored_by_me: 'Authored by me',
|
||||
invite: 'Invite',
|
||||
email: 'Email',
|
||||
approved_by: 'Approved by',
|
||||
reviewed_by: 'Reviewed by',
|
||||
authored_by: 'Authored by',
|
||||
@@ -85,6 +87,8 @@ const en = {
|
||||
}
|
||||
|
||||
const es = {
|
||||
invite: 'Invitar',
|
||||
email: 'Correo electrónico',
|
||||
approved: 'Aprobado',
|
||||
reviewed: 'Revisado',
|
||||
other: 'Otro',
|
||||
@@ -170,6 +174,8 @@ const es = {
|
||||
}
|
||||
|
||||
const it = {
|
||||
invite: 'Invita',
|
||||
email: 'Email',
|
||||
approved: 'Approvato',
|
||||
reviewed: 'Revisionato',
|
||||
other: 'Altro',
|
||||
@@ -255,6 +261,8 @@ const it = {
|
||||
}
|
||||
|
||||
const de = {
|
||||
invite: 'Einladen',
|
||||
email: 'E-Mail',
|
||||
approved: 'Genehmigt',
|
||||
reviewed: 'Überprüft',
|
||||
other: 'Andere',
|
||||
@@ -340,6 +348,8 @@ const de = {
|
||||
}
|
||||
|
||||
const fr = {
|
||||
invite: 'Inviter',
|
||||
email: 'Courriel',
|
||||
approved: 'Approuvé',
|
||||
reviewed: 'Révisé',
|
||||
other: 'Autre',
|
||||
@@ -425,6 +435,8 @@ const fr = {
|
||||
}
|
||||
|
||||
const pl = {
|
||||
invite: 'Zaproś',
|
||||
email: 'E-mail',
|
||||
approved: 'Zaakceptowany',
|
||||
reviewed: 'Przejrzany',
|
||||
other: 'Inny',
|
||||
@@ -510,6 +522,8 @@ const pl = {
|
||||
}
|
||||
|
||||
const uk = {
|
||||
invite: 'Запросити',
|
||||
email: 'Електронна пошта',
|
||||
approved: 'Затверджено',
|
||||
reviewed: 'Переглянуто',
|
||||
other: 'Інше',
|
||||
@@ -595,6 +609,8 @@ const uk = {
|
||||
}
|
||||
|
||||
const cs = {
|
||||
invite: 'Pozvat',
|
||||
email: 'E-mail',
|
||||
approved: 'Schváleno',
|
||||
reviewed: 'Zkontrolováno',
|
||||
other: 'Jiné',
|
||||
@@ -680,6 +696,8 @@ const cs = {
|
||||
}
|
||||
|
||||
const pt = {
|
||||
invite: 'Convidar',
|
||||
email: 'E-mail',
|
||||
approved: 'Aprovado',
|
||||
reviewed: 'Revisado',
|
||||
other: 'Outro',
|
||||
@@ -765,6 +783,8 @@ const pt = {
|
||||
}
|
||||
|
||||
const he = {
|
||||
invite: 'הזמן',
|
||||
email: 'דוא"ל',
|
||||
approved: 'מאושר',
|
||||
reviewed: 'נסקר',
|
||||
other: 'אחר',
|
||||
@@ -851,6 +871,8 @@ const he = {
|
||||
}
|
||||
|
||||
const nl = {
|
||||
invite: 'Uitnodigen',
|
||||
email: 'E-mail',
|
||||
approved: 'Goedgekeurd',
|
||||
reviewed: 'Beoordeeld',
|
||||
other: 'Anders',
|
||||
@@ -937,6 +959,8 @@ const nl = {
|
||||
}
|
||||
|
||||
const ar = {
|
||||
invite: 'دعوة',
|
||||
email: 'البريد الإلكتروني',
|
||||
approved: 'موافق عليه',
|
||||
reviewed: 'تمت مراجعته',
|
||||
other: 'آخر',
|
||||
@@ -1022,6 +1046,8 @@ const ar = {
|
||||
}
|
||||
|
||||
const ko = {
|
||||
invite: '초대하기',
|
||||
email: '이메일',
|
||||
approved: '승인됨',
|
||||
reviewed: '검토됨',
|
||||
other: '기타',
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
<template>
|
||||
<form
|
||||
ref="form"
|
||||
action="post"
|
||||
method="post"
|
||||
class="mx-auto"
|
||||
@submit.prevent="submit"
|
||||
>
|
||||
<input
|
||||
type="hidden"
|
||||
name="authenticity_token"
|
||||
:value="authenticityToken"
|
||||
>
|
||||
<div
|
||||
v-for="(submitter, index) in submitters"
|
||||
:key="submitter.uuid"
|
||||
:class="{ 'mt-4': index !== 0 }"
|
||||
>
|
||||
<input
|
||||
:value="submitter.uuid"
|
||||
hidden
|
||||
name="submission[submitters][][uuid]"
|
||||
>
|
||||
<label
|
||||
:for="submitter.uuid"
|
||||
dir="auto"
|
||||
class="label text-2xl"
|
||||
>
|
||||
{{ t('invite') }} {{ submitter.name }}
|
||||
</label>
|
||||
<input
|
||||
:id="submitter.uuid"
|
||||
dir="auto"
|
||||
class="base-input !text-2xl w-full"
|
||||
:placeholder="t('email')"
|
||||
type="email"
|
||||
required
|
||||
autofocus="true"
|
||||
name="submission[submitters][][email]"
|
||||
>
|
||||
</div>
|
||||
<div
|
||||
class="mt-6 md:mt-8"
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
class="base-button w-full flex justify-center"
|
||||
:disabled="isSubmitting"
|
||||
>
|
||||
<span class="flex">
|
||||
<IconInnerShadowTop
|
||||
v-if="isSubmitting"
|
||||
class="mr-1 animate-spin"
|
||||
/>
|
||||
<span>
|
||||
{{ t('submit') }}
|
||||
</span><span
|
||||
v-if="isSubmitting"
|
||||
class="w-6 flex justify-start mr-1"
|
||||
><span>...</span></span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { IconInnerShadowTop } from '@tabler/icons-vue'
|
||||
|
||||
export default {
|
||||
name: 'InviteForm',
|
||||
components: {
|
||||
IconInnerShadowTop
|
||||
},
|
||||
inject: ['t'],
|
||||
props: {
|
||||
submitters: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
authenticityToken: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
submitterSlug: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['success'],
|
||||
data () {
|
||||
return {
|
||||
isSubmitting: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit () {
|
||||
this.isSubmitting = true
|
||||
|
||||
return fetch(this.url, {
|
||||
method: 'POST',
|
||||
body: new FormData(this.$refs.form)
|
||||
}).then((response) => {
|
||||
if (response.status === 200) {
|
||||
this.$emit('success')
|
||||
}
|
||||
}).finally(() => {
|
||||
this.isSubmitting = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -47,6 +47,7 @@ class SubmissionEvent < ApplicationRecord
|
||||
phone_verified: 'phone_verified',
|
||||
start_form: 'start_form',
|
||||
view_form: 'view_form',
|
||||
invite_party: 'invite_party',
|
||||
complete_form: 'complete_form',
|
||||
decline_form: 'decline_form',
|
||||
api_complete_form: 'api_complete_form'
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<%= button_to button_title(title: t('send_copy_to_email'), disabled_with: t('sending'), icon: svg_icon('mail_forward', class: 'w-6 h-6')), send_submission_email_index_path, params: { submitter_slug: @submitter.slug }, class: 'base-button w-full' %>
|
||||
</toggle-submit>
|
||||
<% end %>
|
||||
<% if @template.submitters.to_a.size == 1 && %w[api embed].exclude?(@submitter.submission.source) && @submitter.account.account_configs.find_or_initialize_by(key: AccountConfig::ALLOW_TO_RESUBMIT).value != false %>
|
||||
<% if Templates.filter_undefined_submitters(@template).size == 1 && %w[api embed].exclude?(@submitter.submission.source) && @submitter.account.account_configs.find_or_initialize_by(key: AccountConfig::ALLOW_TO_RESUBMIT).value != false %>
|
||||
<toggle-submit class="block">
|
||||
<%= button_to button_title(title: t('resubmit'), disabled_with: t('resubmit'), icon: svg_icon('reload', class: 'w-6 h-6')), start_form_path(@template.slug), params: { submitter: { email: params[:email] }, resubmit: @submitter.slug }, method: :put, class: 'white-button w-full' %>
|
||||
</toggle-submit>
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<%= form_for '', url: template_submissions_path(template), html: { class: 'space-y-4', autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %>
|
||||
<% submitters = template.submitters.reject { |e| e['invite_by_uuid'].present? } %>
|
||||
<dynamic-list class="space-y-4">
|
||||
<div class="space-y-4">
|
||||
<div class="card card-compact bg-base-200" data-targets="dynamic-list.items">
|
||||
<div class="card-body">
|
||||
<div class="absolute right-4 top-5">
|
||||
<a href="#" data-action="click:dynamic-list#removeItem" class="<%= template.submitters.size == 1 ? 'right-2' : '-top-3' %> relative block w-6 h-6 rounded-lg text-neutral-700 text-center bg-base-300 p-1 hidden hover:bg-neutral hover:text-white">
|
||||
<a href="#" data-action="click:dynamic-list#removeItem" class="<%= submitters.size == 1 ? 'right-2' : '-top-3' %> relative block w-6 h-6 rounded-lg text-neutral-700 text-center bg-base-300 p-1 hidden hover:bg-neutral hover:text-white">
|
||||
<%= svg_icon('trash', class: 'w-4 h-4') %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="grid <%= 'md:grid-cols-2' if template.submitters.size > 1 %> gap-4">
|
||||
<% template.submitters.each_with_index do |item, index| %>
|
||||
<div class="grid <%= 'md:grid-cols-2' if submitters.size > 1 %> gap-4">
|
||||
<% submitters.each_with_index do |item, index| %>
|
||||
<submitter-item class="form-control">
|
||||
<% if template.submitters.size > 1 %>
|
||||
<% if submitters.size > 1 %>
|
||||
<label class="label pt-0 pb-1 text-xs">
|
||||
<span class="label-text"> <%= item['name'] %></span>
|
||||
</label>
|
||||
@@ -22,7 +23,7 @@
|
||||
<%= tag.input type: 'text', name: 'submission[1][submitters][][name]', autocomplete: 'off', class: 'input input-sm input-bordered w-full', placeholder: 'Name', required: index.zero?, value: (params[:selfsign] && index.zero?) || item['is_requester'] ? current_user.full_name : '', dir: 'auto', id: "detailed_name_#{item['uuid']}" %>
|
||||
</linked-input>
|
||||
</submitters-autocomplete>
|
||||
<div class="grid <%= 'md:grid-cols-2 gap-1' if template.submitters.size == 1 %>">
|
||||
<div class="grid <%= 'md:grid-cols-2 gap-1' if submitters.size == 1 %>">
|
||||
<submitters-autocomplete data-field="email">
|
||||
<linked-input data-target-id="<%= "detailed_email_#{item['linked_to_uuid']}" if item['linked_to_uuid'].present? %>">
|
||||
<input type="email" multiple name="submission[1][submitters][][email]" autocomplete="off" class="input input-sm input-bordered mt-1.5 w-full" placeholder="Email (optional)" value="<%= item['email'].presence || ((params[:selfsign] && index.zero?) || item['is_requester'] ? current_user.email : '') %>" id="detailed_email_<%= item['uuid'] %>">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<%= form_for '', url: template_submissions_path(template), html: { class: 'space-y-4', autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %>
|
||||
<% if template.submitters.size == 1 %>
|
||||
<% submitters = template.submitters.reject { |e| e['invite_by_uuid'].present? } %>
|
||||
<% if submitters.size == 1 %>
|
||||
<submitter-item class="form-control">
|
||||
<emails-textarea data-bulk-enabled="<%= Docuseal.demo? || !Docuseal.multitenant? || can?(:manage, :bulk_send) %>" data-limit="<%= Docuseal.multitenant? ? (can?(:manage, :bulk_send) ? 40 : 1) : nil %>">
|
||||
<submitters-autocomplete data-field="email" class="block relative">
|
||||
@@ -20,7 +21,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="grid md:grid-cols-2 gap-4">
|
||||
<% template.submitters.each_with_index do |item, index| %>
|
||||
<% submitters.each_with_index do |item, index| %>
|
||||
<submitter-item class="form-control">
|
||||
<label class="label pt-0 pb-1 text-xs">
|
||||
<span class="label-text"> <%= item['name'] %></span>
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
<%= form_for '', url: template_submissions_path(template), html: { class: 'space-y-4', autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %>
|
||||
<% submitters = template.submitters.reject { |e| e['invite_by_uuid'].present? } %>
|
||||
<dynamic-list class="space-y-4">
|
||||
<div class="space-y-4">
|
||||
<div class="card card-compact bg-base-200" data-targets="dynamic-list.items">
|
||||
<div class="card-body">
|
||||
<div class="absolute right-4 top-5">
|
||||
<a href="#" data-action="click:dynamic-list#removeItem" class="<%= template.submitters.size == 1 ? 'right-2' : '-top-3' %> relative block w-6 h-6 rounded-lg text-neutral-700 text-center bg-base-300 p-1 hidden hover:bg-neutral hover:text-white">
|
||||
<a href="#" data-action="click:dynamic-list#removeItem" class="<%= submitters.size == 1 ? 'right-2' : '-top-3' %> relative block w-6 h-6 rounded-lg text-neutral-700 text-center bg-base-300 p-1 hidden hover:bg-neutral hover:text-white">
|
||||
<%= svg_icon('trash', class: 'w-4 h-4') %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="grid <%= template.submitters.size > 1 ? 'md:grid-cols-2 gap-4' : 'gap-1' %>">
|
||||
<% template.submitters.each_with_index do |item, index| %>
|
||||
<submitter-item class="grid <%= template.submitters.size > 1 ? 'gap-4' : 'md:grid-cols-2 gap-1' %>">
|
||||
<div class="grid <%= submitters.size > 1 ? 'md:grid-cols-2 gap-4' : 'gap-1' %>">
|
||||
<% submitters.each_with_index do |item, index| %>
|
||||
<submitter-item class="grid <%= submitters.size > 1 ? 'gap-4' : 'md:grid-cols-2 gap-1' %>">
|
||||
<div class="form-control">
|
||||
<% if template.submitters.size > 1 %>
|
||||
<% if submitters.size > 1 %>
|
||||
<label class="label pt-0 pb-1 text-xs">
|
||||
<span class="label-text"> <%= item['name'] %></span>
|
||||
</label>
|
||||
@@ -23,7 +24,7 @@
|
||||
<%= tag.input type: 'tel', pattern: '^\+[0-9\s\-]+$', oninvalid: "this.value ? this.setCustomValidity('Use internatioanl format: +1xxx...') : ''", oninput: "this.setCustomValidity('')", name: 'submission[1][submitters][][phone]', autocomplete: 'off', class: 'input input-sm input-bordered w-full', placeholder: 'Phone', required: index.zero?, id: "phone_phone_#{item['uuid']}" %>
|
||||
</linked-input>
|
||||
</submitters-autocomplete>
|
||||
<% if template.submitters.size > 1 %>
|
||||
<% if submitters.size > 1 %>
|
||||
<submitters-autocomplete data-field="name">
|
||||
<linked-input data-target-id="<%= "phone_name_#{item['linked_to_uuid']}" if item['linked_to_uuid'].present? %>">
|
||||
<input type="text" name="submission[1][submitters][][name]" autocomplete="off" class="input input-sm input-bordered mt-1.5 w-full" placeholder="Name (optional)" value="<%= (params[:selfsign] && index.zero?) || item['is_requester'] ? current_user.full_name : '' %>" dir="auto" id="phone_name_<%= item['uuid'] %>">
|
||||
@@ -31,7 +32,7 @@
|
||||
</submitters-autocomplete>
|
||||
<% end %>
|
||||
</div>
|
||||
<% if template.submitters.size == 1 %>
|
||||
<% if submitters.size == 1 %>
|
||||
<div class="form-control flex">
|
||||
<submitters-autocomplete data-field="name">
|
||||
<linked-input data-target-id="<%= "phone_name_#{item['linked_to_uuid']}" if item['linked_to_uuid'].present? %>">
|
||||
|
||||
@@ -145,8 +145,10 @@
|
||||
<span>
|
||||
<% if submitter&.declined_at? %>
|
||||
Declined on <%= l(submitter.declined_at.in_time_zone(@submission.account.timezone), format: :short, locale: @submission.account.locale) %>
|
||||
<% elsif submitter %>
|
||||
<%= submitter.completed_at? ? l(submitter.completed_at.in_time_zone(@submission.account.timezone), format: :long, locale: @submission.account.locale) : 'Not completed yet' %>
|
||||
<% else %>
|
||||
<%= submitter&.completed_at? ? l(submitter.completed_at.in_time_zone(@submission.account.timezone), format: :long, locale: @submission.account.locale) : 'Not completed yet' %>
|
||||
Not invited yet
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<% data_attachments = attachments_index.values.select { |e| e.record_id == submitter.id }.to_json(only: %i[uuid created_at], methods: %i[url filename content_type]) %>
|
||||
<% data_fields = (submitter.submission.template_fields || submitter.submission.template.fields).select { |f| f['submitter_uuid'] == submitter.uuid }.to_json %>
|
||||
<submission-form data-is-demo="<%= Docuseal.demo? %>" data-require-signing-reason="<%= configs[:require_signing_reason] %>" data-with-signature-id="<%= configs[:with_signature_id] %>" data-with-confetti="<%= configs[:with_confetti] %>" data-completed-redirect-url="<%= submitter.preferences['completed_redirect_url'] %>" data-completed-message="<%= configs[:completed_message].to_json %>" data-completed-button="<%= configs[:completed_button].to_json %>" data-go-to-last="<%= submitter.preferences.key?('go_to_last') ? submitter.preferences['go_to_last'] : submitter.opened_at? %>" data-submitter="<%= submitter.to_json(only: %i[uuid slug name phone email]) %>" data-can-send-email="<%= Accounts.can_send_emails?(submitter.submission.account) %>" data-attachments="<%= data_attachments %>" data-fields="<%= data_fields %>" data-values="<%= submitter.values.to_json %>" data-with-typed-signature="<%= configs[:with_typed_signature] %>" data-previous-signature-value="<%= local_assigns[:signature_attachment]&.uuid %>" data-remember-signature="<%= configs[:prefill_signature] %>" data-dry-run="<%= local_assigns[:dry_run] %>" data-expand="<%= local_assigns[:expand] %>" data-scroll-padding="<%= local_assigns[:scroll_padding] %>"></submission-form>
|
||||
<% 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 %>
|
||||
<submission-form data-is-demo="<%= Docuseal.demo? %>" data-require-signing-reason="<%= configs[:require_signing_reason] %>" data-with-signature-id="<%= configs[:with_signature_id] %>" data-with-confetti="<%= configs[:with_confetti] %>" data-completed-redirect-url="<%= submitter.preferences['completed_redirect_url'] %>" data-completed-message="<%= configs[:completed_message].to_json %>" data-completed-button="<%= configs[:completed_button].to_json %>" data-go-to-last="<%= submitter.preferences.key?('go_to_last') ? submitter.preferences['go_to_last'] : submitter.opened_at? %>" data-submitter="<%= submitter.to_json(only: %i[uuid slug name phone email]) %>" data-can-send-email="<%= Accounts.can_send_emails?(submitter.submission.account) %>" data-invite-submitters="<%= invite_submitters %>" data-attachments="<%= data_attachments %>" data-fields="<%= data_fields %>" data-values="<%= submitter.values.to_json %>" data-with-typed-signature="<%= configs[:with_typed_signature] %>" data-previous-signature-value="<%= local_assigns[:signature_attachment]&.uuid %>" data-remember-signature="<%= configs[:prefill_signature] %>" data-dry-run="<%= local_assigns[:dry_run] %>" data-expand="<%= local_assigns[:expand] %>" data-scroll-padding="<%= local_assigns[:scroll_padding] %>"></submission-form>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</download-button>
|
||||
<% end %>
|
||||
</div>
|
||||
<% if @submitter.submission.template.submitters.size == 1 && %w[api embed].exclude?(@submitter.submission.source) && @submitter.account.account_configs.find_or_initialize_by(key: AccountConfig::ALLOW_TO_RESUBMIT).value != false && !@submitter.template.archived_at? %>
|
||||
<% if Templates.filter_undefined_submitters(@submitter.submission.template).size == 1 && %w[api embed].exclude?(@submitter.submission.source) && @submitter.account.account_configs.find_or_initialize_by(key: AccountConfig::ALLOW_TO_RESUBMIT).value != false && !@submitter.template.archived_at? %>
|
||||
<div class="divider uppercase"><%= t('or') %></div>
|
||||
<toggle-submit class="block">
|
||||
<%= button_to button_title(title: t('resubmit'), disabled_with: t('resubmit'), icon: svg_icon('reload', class: 'w-6 h-6')), start_form_path(@submitter.submission.template.slug), params: { submitter: { email: @submitter.email, phone: @submitter.phone, name: @submitter.name }, resubmit: @submitter.slug }, method: :put, class: 'white-button w-full' %>
|
||||
|
||||
@@ -184,22 +184,22 @@
|
||||
<div class="space-y-3 divide-y">
|
||||
<% @template.submitters.each_with_index do |submitter, index| %>
|
||||
<div class="pt-3">
|
||||
<%= f.fields_for :submitters, item = Struct.new(:name, :uuid, :is_requester, :email, :linked_to_uuid, :option).new(*submitter.values_at('name', 'uuid', 'is_requester', 'email', 'linked_to_uuid')), index: do |ff| %>
|
||||
<% item.option = item.is_requester.present? ? 'is_requester' : (item.email.present? ? 'email' : (item.linked_to_uuid.present? ? "linked_to_#{item.linked_to_uuid}" : '')) %>
|
||||
<%= f.fields_for :submitters, item = Struct.new(:name, :uuid, :is_requester, :email, :invite_by_uuid, :linked_to_uuid, :option).new(*submitter.values_at('name', 'uuid', 'is_requester', 'email', 'invite_by_uuid', 'linked_to_uuid')), index: do |ff| %>
|
||||
<% item.option = item.is_requester.present? ? 'is_requester' : (item.email.present? ? 'email' : (item.linked_to_uuid.present? ? "linked_to_#{item.linked_to_uuid}" : (item.invite_by_uuid.present? ? "invite_by_#{item.invite_by_uuid}" : ''))) %>
|
||||
<%= ff.hidden_field :uuid %>
|
||||
<div class="form-control">
|
||||
<%= ff.text_field :name, class: 'w-full outline-none border-transparent focus:border-transparent focus:ring-0 bg-base-100 px-1 peer mb-2', autocomplete: 'off', placeholder: "#{index + 1}#{(index + 1).ordinal} Party", required: true %>
|
||||
<% if @template.submitters.size == 2 %>
|
||||
<%= ff.email_field :email, class: 'base-input', autocomplete: 'off', placeholder: 'Default Email', disabled: ff.object.is_requester, id: field_uuid = SecureRandom.uuid %>
|
||||
<%= ff.email_field :email, class: 'base-input', autocomplete: 'off', placeholder: 'Default Email', disabled: ff.object.is_requester || ff.object.invite_by_uuid.present?, id: field_uuid = SecureRandom.uuid %>
|
||||
<% else %>
|
||||
<toggle-attribute data-target-id="<%= email_field_uuid = SecureRandom.uuid %>" data-class-name="hidden" data-value="email">
|
||||
<%= ff.select :option, [['Not specified', 'not_set'], ['Submission requester', 'is_requester'], ['Specified email', 'email'], *(@template.submitters - [submitter]).map { |e| ["Same as #{e['name']}", "linked_to_#{e['uuid']}"] }], {}, class: 'base-select mb-3' %>
|
||||
<%= ff.select :option, [['Not specified', 'not_set'], ['Submission requester', 'is_requester'], ['Specified email', 'email'], *(@template.submitters - [submitter]).map { |e| ["Invite by #{e['name']}", "invite_by_#{e['uuid']}"] }, *(@template.submitters - [submitter]).map { |e| ["Same as #{e['name']}", "linked_to_#{e['uuid']}"] }], {}, class: 'base-select mb-3' %>
|
||||
</toggle-attribute>
|
||||
<%= ff.email_field :email, class: "base-input #{'hidden' if item.option != 'email'}", autocomplete: 'off', placeholder: 'Default Email', id: email_field_uuid %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% if @template.submitters.size == 2 %>
|
||||
<div class="mt-3">
|
||||
<checkbox-group class="mt-3 flex items-center space-x-4">
|
||||
<label class="flex items-center space-x-2 cursor-pointer">
|
||||
<toggle-attribute data-target-id="<%= field_uuid %>" class="flex" data-attribute="disabled">
|
||||
<%= ff.check_box :is_requester, class: 'base-checkbox' %>
|
||||
@@ -208,7 +208,17 @@
|
||||
Submission requester
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<% if index == 1 %>
|
||||
<label class="flex items-center space-x-2 cursor-pointer">
|
||||
<toggle-attribute data-target-id="<%= field_uuid %>" class="flex" data-attribute="disabled">
|
||||
<%= ff.check_box :invite_by_uuid, { class: 'base-checkbox' }, @template.submitters.first['uuid'], '' %>
|
||||
</toggle-attribute>
|
||||
<span class="select-none">
|
||||
Invite by <%= @template.submitters.first['name'] %>
|
||||
</span>
|
||||
</label>
|
||||
<% end %>
|
||||
</checkbox-group>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -128,6 +128,7 @@ Rails.application.routes.draw do
|
||||
resources :values, only: %i[index], controller: 'submit_form_values'
|
||||
resources :download, only: %i[index], controller: 'submit_form_download'
|
||||
resources :decline, only: %i[create], controller: 'submit_form_decline'
|
||||
resources :invite, only: %i[create], controller: 'submit_form_invite'
|
||||
get :completed
|
||||
end
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ module SubmissionEvents
|
||||
phone_verified: 'Phone verified',
|
||||
start_form: 'Submission started',
|
||||
view_form: 'Form viewed',
|
||||
invite_party: 'Invited',
|
||||
complete_form: 'Submission completed',
|
||||
api_complete_form: 'Submission completed via API'
|
||||
}.freeze
|
||||
|
||||
@@ -10,14 +10,6 @@ module Submissions
|
||||
assign_defined_submitters(submission)
|
||||
assign_linked_submitters(submission)
|
||||
|
||||
if submission.submitters.size == 1 && submission.template.submitters.size == 2 && submission.source != 'embed'
|
||||
submission.submitters.new(
|
||||
account_id: submission.account_id,
|
||||
uuid: submission.template.submitters.find { |e| e['uuid'] != submission.submitters.first.uuid }['uuid'],
|
||||
email: submission.template.author.email
|
||||
)
|
||||
end
|
||||
|
||||
submission
|
||||
end
|
||||
|
||||
|
||||
@@ -39,10 +39,21 @@ module Submissions
|
||||
|
||||
next if submission.submitters.blank?
|
||||
|
||||
maybe_add_invite_submitters(submission, template)
|
||||
|
||||
submission.tap(&:save!)
|
||||
end
|
||||
end
|
||||
|
||||
def maybe_add_invite_submitters(submission, template)
|
||||
template.submitters.each do |item|
|
||||
next if item['invite_by_uuid'].blank? ||
|
||||
submission.template_submitters.any? { |e| e['uuid'] == item['uuid'] }
|
||||
|
||||
submission.template_submitters << item
|
||||
end
|
||||
end
|
||||
|
||||
def maybe_set_template_fields(submission, submitters_attrs, default_submitter_uuid: nil)
|
||||
template_fields = (submission.template_fields || submission.template.fields).deep_dup
|
||||
|
||||
|
||||
@@ -348,13 +348,21 @@ module Submissions
|
||||
|
||||
events_data = submission.submission_events.sort_by(&:event_timestamp).map do |event|
|
||||
submitter = submission.submitters.find { |e| e.id == event.submitter_id }
|
||||
|
||||
text = SubmissionEvents::EVENT_NAMES[event.event_type.to_sym]
|
||||
|
||||
if event.event_type == 'invite_party' &&
|
||||
(invited_submitter = submission.submitters.find { |e| e.uuid == event.data['uuid'] }) &&
|
||||
(name = submission.template_submitters.find { |e| e['uuid'] == event.data['uuid'] }&.dig('name'))
|
||||
text += ['', invited_submitter.name || invited_submitter.email || invited_submitter.phone, name].join(' ')
|
||||
end
|
||||
|
||||
[
|
||||
"#{I18n.l(event.event_timestamp.in_time_zone(account.timezone), format: :long, locale: account.locale)} " \
|
||||
"#{TimeUtils.timezone_abbr(account.timezone, event.event_timestamp)}",
|
||||
composer.document.layout.formatted_text_box(
|
||||
[
|
||||
{ text: SubmissionEvents::EVENT_NAMES[event.event_type.to_sym],
|
||||
font: [FONT_NAME, { variant: :bold }] },
|
||||
{ text:, font: [FONT_NAME, { variant: :bold }] },
|
||||
event.event_type.include?('send_') ? ' to ' : ' by ',
|
||||
if event.event_type.include?('sms') || event.event_type.include?('phone')
|
||||
event.data['phone'] || submitter.phone
|
||||
|
||||
@@ -23,4 +23,11 @@ module Templates
|
||||
|
||||
templates.where(Template.arel_table[:name].lower.matches("%#{keyword.downcase}%"))
|
||||
end
|
||||
|
||||
def filter_undefined_submitters(template)
|
||||
template.submitters.to_a.select do |item|
|
||||
item['invite_by_uuid'].blank? && item['linked_to_uuid'].blank? &&
|
||||
item['is_requester'].blank? && item['email'].blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user