parent
d9eab9f254
commit
d2193bf428
@ -2,56 +2,19 @@
|
|||||||
import { _ } from "svelte-i18n";
|
import { _ } from "svelte-i18n";
|
||||||
import { clickOutside } from "../base/outsideclick";
|
import { clickOutside } from "../base/outsideclick";
|
||||||
import { focusTrap } from "svelte-focus-trap";
|
import { focusTrap } from "svelte-focus-trap";
|
||||||
import {
|
|
||||||
RunnerService,
|
|
||||||
RunnerTeamService,
|
|
||||||
RunnerOrganizationService,
|
|
||||||
} from "@odit/lfk-client-js";
|
|
||||||
import isEmail from "validator/es/lib/isEmail";
|
|
||||||
import isMobilePhone from "validator/es/lib/isMobilePhone";
|
|
||||||
import Toastify from "toastify-js";
|
import Toastify from "toastify-js";
|
||||||
|
import { UserGroupService } from "@odit/lfk-client-js";
|
||||||
export let modal_open;
|
export let modal_open;
|
||||||
export let current_runners;
|
export let current_groups;
|
||||||
$: selected_team = undefined;
|
let description_input_value;
|
||||||
let firstname_input;
|
|
||||||
let lastname_input;
|
|
||||||
let middlename_input;
|
|
||||||
let phone_input;
|
|
||||||
let email_input;
|
|
||||||
let teams = [];
|
|
||||||
RunnerTeamService.runnerTeamControllerGetAll().then((val) => {
|
|
||||||
teams = val;
|
|
||||||
});
|
|
||||||
let orgs = [];
|
|
||||||
RunnerOrganizationService.runnerOrganizationControllerGetAll().then((val) => {
|
|
||||||
orgs = val;
|
|
||||||
});
|
|
||||||
function focus(el) {
|
function focus(el) {
|
||||||
el.focus();
|
el.focus();
|
||||||
}
|
}
|
||||||
$: middlename_input_value = "";
|
$: description_input_value = "";
|
||||||
$: phone_input_value = "";
|
$: name_input_value = "";
|
||||||
$: email_input_value = "";
|
|
||||||
$: lastname_input_value = "";
|
|
||||||
$: firstname_input_value = "";
|
|
||||||
$: processed_last_submit = true;
|
$: processed_last_submit = true;
|
||||||
$: isPhoneValidOrEmpty =
|
$: isNameValid = name_input_value.trim().length !== 0;
|
||||||
isMobilePhone(
|
$: createbtnenabled = isNameValid;
|
||||||
phone_input_value
|
|
||||||
.replaceAll("(", "")
|
|
||||||
.replaceAll(")", "")
|
|
||||||
.replaceAll("-", "")
|
|
||||||
.replaceAll(" ", "")
|
|
||||||
) || phone_input_value === "";
|
|
||||||
$: isEmailValidOrEmpty =
|
|
||||||
isEmail(email_input_value) || email_input_value === "";
|
|
||||||
$: isLastnameValid = lastname_input_value.trim().length !== 0;
|
|
||||||
$: isFirstnameValid = firstname_input_value.trim().length !== 0;
|
|
||||||
$: createbtnenabled =
|
|
||||||
isFirstnameValid &&
|
|
||||||
isLastnameValid &&
|
|
||||||
isEmailValidOrEmpty &&
|
|
||||||
isPhoneValidOrEmpty;
|
|
||||||
(() => {
|
(() => {
|
||||||
document.onkeydown = (e) => {
|
document.onkeydown = (e) => {
|
||||||
e = e || window.event;
|
e = e || window.event;
|
||||||
@ -70,38 +33,26 @@
|
|||||||
if (processed_last_submit === true) {
|
if (processed_last_submit === true) {
|
||||||
processed_last_submit = false;
|
processed_last_submit = false;
|
||||||
const toast = Toastify({
|
const toast = Toastify({
|
||||||
text: "Runner is being added...",
|
text: "Group is being added...",
|
||||||
duration: -1,
|
duration: -1,
|
||||||
}).showToast();
|
}).showToast();
|
||||||
let postdata = {
|
let postdata = {
|
||||||
group: selected_team,
|
name: name_input_value,
|
||||||
firstname: firstname_input_value,
|
description: description_input_value
|
||||||
lastname: lastname_input_value,
|
|
||||||
};
|
|
||||||
if (middlename_input_value) {
|
|
||||||
postdata.middlename = middlename_input_value;
|
|
||||||
}
|
}
|
||||||
if (phone_input_value) {
|
UserGroupService.userGroupControllerPost(postdata)
|
||||||
postdata.phone = phone_input_value;
|
|
||||||
}
|
|
||||||
if (email_input_value) {
|
|
||||||
postdata.email = email_input_value;
|
|
||||||
}
|
|
||||||
RunnerService.runnerControllerPost(postdata)
|
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
firstname_input_value = "";
|
name_input_value = "";
|
||||||
lastname_input_value = "";
|
description_input_value = "";
|
||||||
middlename_input_value = "";
|
|
||||||
email_input_value = "";
|
|
||||||
modal_open = false;
|
modal_open = false;
|
||||||
//
|
//
|
||||||
Toastify({
|
Toastify({
|
||||||
text: "Runner added",
|
text: "Group added",
|
||||||
duration: 500,
|
duration: 500,
|
||||||
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
|
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
|
||||||
}).showToast();
|
}).showToast();
|
||||||
current_runners.push(result);
|
current_groups.push(result);
|
||||||
current_runners = current_runners;
|
current_groups = current_groups;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
//
|
//
|
||||||
@ -154,136 +105,48 @@
|
|||||||
</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">
|
||||||
{$_('create-a-new-runner')}
|
Create a new user group
|
||||||
</h3>
|
</h3>
|
||||||
<div class="mt-2 mb-6">
|
<div class="mt-2 mb-6">
|
||||||
<p class="text-sm text-gray-500">
|
<p class="text-sm text-gray-500">
|
||||||
{$_('please-provide-the-required-information-to-add-a-new-runner')}
|
Please provide the required information for creating a new user group.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-6 gap-6">
|
<div class="grid grid-cols-6 gap-6">
|
||||||
<div class="col-span-6">
|
<div class="col-span-6">
|
||||||
<label
|
<label
|
||||||
for="firstname"
|
for="firstname"
|
||||||
class="block text-sm font-medium text-gray-700">{$_('first-name')}</label>
|
class="block text-sm font-medium text-gray-700">Name</label>
|
||||||
<input
|
<input
|
||||||
use:focus
|
use:focus
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder={$_('first-name')}
|
placeholder="Name"
|
||||||
class:border-red-500={!isFirstnameValid}
|
class:border-red-500={!isNameValid}
|
||||||
class:focus:border-red-500={!isFirstnameValid}
|
class:focus:border-red-500={!isNameValid}
|
||||||
class:focus:ring-red-500={!isFirstnameValid}
|
class:focus:ring-red-500={!isNameValid}
|
||||||
bind:value={firstname_input_value}
|
bind:value={name_input_value}
|
||||||
bind:this={firstname_input}
|
|
||||||
type="text"
|
type="text"
|
||||||
name="firstname"
|
name="firstname"
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
||||||
{#if !isFirstnameValid}
|
{#if !isNameValid}
|
||||||
<span
|
<span
|
||||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
||||||
{$_('first-name-is-required')}
|
Name is required
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-6">
|
<div class="col-span-6">
|
||||||
<label
|
<label
|
||||||
for="trackname"
|
for="trackname"
|
||||||
class="block text-sm font-medium text-gray-700">{$_('middle-name')}</label>
|
class="block text-sm font-medium text-gray-700">Description(optional)</label>
|
||||||
<input
|
<input
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder={$_('middle-name')}
|
placeholder="Something about the group.."
|
||||||
bind:value={middlename_input_value}
|
bind:value={description_input_value}
|
||||||
bind:this={middlename_input}
|
|
||||||
type="text"
|
type="text"
|
||||||
name="trackname"
|
name="trackname"
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-span-6">
|
|
||||||
<label
|
|
||||||
for="lastname"
|
|
||||||
class="block text-sm font-medium text-gray-700">Last Name</label>
|
|
||||||
<input
|
|
||||||
autocomplete="off"
|
|
||||||
placeholder="Last Name"
|
|
||||||
class:border-red-500={!isLastnameValid}
|
|
||||||
class:focus:border-red-500={!isLastnameValid}
|
|
||||||
class:focus:ring-red-500={!isLastnameValid}
|
|
||||||
bind:value={lastname_input_value}
|
|
||||||
bind:this={lastname_input}
|
|
||||||
type="text"
|
|
||||||
name="lastname"
|
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
|
||||||
{#if !isLastnameValid}
|
|
||||||
<span
|
|
||||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
|
||||||
{$_('last-name-is-required')}
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<div class="col-span-6">
|
|
||||||
<label
|
|
||||||
for="team"
|
|
||||||
class="block text-sm font-medium text-gray-700">{$_('team')}</label>
|
|
||||||
<select
|
|
||||||
name="team"
|
|
||||||
bind:value={selected_team}
|
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2">
|
|
||||||
{#each teams as team}
|
|
||||||
<option value={team.id}>
|
|
||||||
{team.parentGroup.name}
|
|
||||||
>
|
|
||||||
{team.name}
|
|
||||||
</option>
|
|
||||||
{/each}
|
|
||||||
{#each orgs as org}
|
|
||||||
<option value={org.id}>{org.name}</option>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col-span-6">
|
|
||||||
<label
|
|
||||||
for="phone"
|
|
||||||
class="block text-sm font-medium text-gray-700">Phone</label>
|
|
||||||
<input
|
|
||||||
autocomplete="off"
|
|
||||||
placeholder="Phone"
|
|
||||||
class:border-red-500={!isPhoneValidOrEmpty}
|
|
||||||
class:focus:border-red-500={!isPhoneValidOrEmpty}
|
|
||||||
class:focus:ring-red-500={!isPhoneValidOrEmpty}
|
|
||||||
bind:value={phone_input_value}
|
|
||||||
bind:this={phone_input}
|
|
||||||
type="tel"
|
|
||||||
name="phone"
|
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
|
||||||
{#if !isPhoneValidOrEmpty}
|
|
||||||
<span
|
|
||||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
|
||||||
{$_('the-provided-phone-number-is-invalid-less-than-br-greater-than-please-enter-a-valid-international-number')}
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<div class="col-span-6">
|
|
||||||
<label
|
|
||||||
for="email"
|
|
||||||
class="block text-sm font-medium text-gray-700">{$_('e-mail-adress')}</label>
|
|
||||||
<input
|
|
||||||
autocomplete="off"
|
|
||||||
placeholder={$_('e-mail-adress')}
|
|
||||||
class:border-red-500={!isEmailValidOrEmpty}
|
|
||||||
class:focus:border-red-500={!isEmailValidOrEmpty}
|
|
||||||
class:focus:ring-red-500={!isEmailValidOrEmpty}
|
|
||||||
bind:value={email_input_value}
|
|
||||||
bind:this={email_input}
|
|
||||||
type="email"
|
|
||||||
name="email"
|
|
||||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
|
||||||
{#if !isEmailValidOrEmpty}
|
|
||||||
<span
|
|
||||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
|
||||||
{$_('valid-email-is-required')}
|
|
||||||
</span>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user