AddContactModal - allow optional address

ref #50
This commit is contained in:
Philipp Dormann 2021-02-15 17:45:20 +01:00
parent 45e7f6a0d1
commit 7138ca1f5f

View File

@ -43,14 +43,17 @@
$: address_zipcode_value = ""; $: address_zipcode_value = "";
$: address_city_value = ""; $: address_city_value = "";
$: processed_last_submit = true; $: processed_last_submit = true;
$: address_checked = true;
$: isPhoneValidOrEmpty = $: isPhoneValidOrEmpty =
phone_input_value.includes("+")&&isMobilePhone( (phone_input_value.includes("+") &&
isMobilePhone(
phone_input_value phone_input_value
.replaceAll("(", "") .replaceAll("(", "")
.replaceAll(")", "") .replaceAll(")", "")
.replaceAll("-", "") .replaceAll("-", "")
.replaceAll(" ", "") .replaceAll(" ", "")
) || phone_input_value === ""; )) ||
phone_input_value === "";
$: isEmailValidOrEmpty = $: isEmailValidOrEmpty =
isEmail(email_input_value) || email_input_value === ""; isEmail(email_input_value) || email_input_value === "";
$: isLastnameValid = lastname_input_value.trim().length !== 0; $: isLastnameValid = lastname_input_value.trim().length !== 0;
@ -62,7 +65,9 @@
isFirstnameValid && isFirstnameValid &&
isLastnameValid && isLastnameValid &&
isEmailValidOrEmpty && isEmailValidOrEmpty &&
isPhoneValidOrEmpty&&isAddress1Valid&&iszipcodevalid&&iscityvalid; isPhoneValidOrEmpty &&
((isAddress1Valid && iszipcodevalid && iscityvalid) ||
address_checked === false);
(() => { (() => {
document.onkeydown = (e) => { document.onkeydown = (e) => {
e = e || window.event; e = e || window.event;
@ -84,18 +89,22 @@
text: "Contact is being added...", text: "Contact is being added...",
duration: -1, duration: -1,
}).showToast(); }).showToast();
const groups=teams.concat(orgs).map(g=>g.id) const groups = teams.concat(orgs).map((g) => g.id);
let postdata = { let address = {};
groups: groups, if (address_checked === true) {
firstname: firstname_input_value, address = {
lastname: lastname_input_value,
address: {
address1: address_input1_value, address1: address_input1_value,
address2: address_input2_value || "", address2: address_input2_value || "",
postalcode: address_zipcode_value, postalcode: address_zipcode_value,
city: address_city_value, city: address_city_value,
country: "DE", country: "DE",
};
} }
let postdata = {
groups,
firstname: firstname_input_value,
lastname: lastname_input_value,
address,
}; };
if (middlename_input_value) { if (middlename_input_value) {
postdata.middlename = middlename_input_value; postdata.middlename = middlename_input_value;
@ -161,8 +170,15 @@
<div class="sm:flex sm:items-start"> <div class="sm:flex sm:items-start">
<div <div
class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10"> class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10">
<svg class="h-6 w-6 text-blue-600" <svg
fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M2 22a8 8 0 1 1 16 0H2zm8-9c-3.315 0-6-2.685-6-6s2.685-6 6-6 6 2.685 6 6-2.685 6-6 6zm10 4h4v2h-4v-2zm-3-5h7v2h-7v-2zm2-5h5v2h-5V7z"/></svg> class="h-6 w-6 text-blue-600"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="24"
height="24"><path fill="none" d="M0 0h24v24H0z" />
<path
d="M2 22a8 8 0 1 1 16 0H2zm8-9c-3.315 0-6-2.685-6-6s2.685-6 6-6 6 2.685 6 6-2.685 6-6 6zm10 4h4v2h-4v-2zm-3-5h7v2h-7v-2zm2-5h5v2h-5V7z" /></svg>
</div> </div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left"> <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-lg leading-6 font-medium text-gray-900"> <h3 class="text-lg leading-6 font-medium text-gray-900">
@ -297,7 +313,22 @@
</span> </span>
{/if} {/if}
</div> </div>
<div class="flex items-start">
<div class="flex items-center h-5">
<input
bind:checked={address_checked}
id="comments"
name="comments"
type="checkbox"
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" />
</div>
<div class="ml-3 text-sm">
<label
for="comments"
class="font-medium text-gray-700">Address</label>
</div>
</div>
{#if address_checked === true}
<div class="col-span-6"> <div class="col-span-6">
<label <label
for="address1" for="address1"
@ -323,7 +354,8 @@
<div class="col-span-6"> <div class="col-span-6">
<label <label
for="address2" for="address2"
class="block text-sm font-medium text-gray-700">Apartment, suite, etc.</label> class="block text-sm font-medium text-gray-700">Apartment,
suite, etc.</label>
<input <input
autocomplete="off" autocomplete="off"
placeholder="Apartment, suite, etc." placeholder="Apartment, suite, etc."
@ -336,7 +368,8 @@
<div class="col-span-6"> <div class="col-span-6">
<label <label
for="zipcode" for="zipcode"
class="block text-sm font-medium text-gray-700">ZIP/ postal code</label> class="block text-sm font-medium text-gray-700">ZIP/
postal code</label>
<input <input
autocomplete="off" autocomplete="off"
placeholder="ZIP/ postal code" placeholder="ZIP/ postal code"
@ -377,6 +410,7 @@
</span> </span>
{/if} {/if}
</div> </div>
{/if}
</div> </div>
</div> </div>
</div> </div>