Skip to content

Commit

Permalink
tweaks in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHo Park committed Jul 26, 2024
1 parent 22b9f4b commit ae71ccb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
10 changes: 7 additions & 3 deletions frontend/src/lib/forms/UserTypeahead.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { FormField, PlainInput, randomFormId } from '$lib/forms';
import { _userTypeaheadSearch, type SingleUserTypeaheadResult } from '$lib/gql/typeahead-queries';
import { _userTypeaheadSearch, _orgMemberTypeaheadSearch, type SingleUserTypeaheadResult } from '$lib/gql/typeahead-queries';
import { overlay } from '$lib/overlay';
import { deriveAsync } from '$lib/util/time';
import { writable } from 'svelte/store';
Expand All @@ -12,11 +12,15 @@
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
export let value: string;
export let debounceMs = 200;
export let isAdmin: boolean;
let input = writable('');
$: $input = value;
let typeaheadResults = deriveAsync(input, _userTypeaheadSearch, [], debounceMs);
let typeaheadResults = deriveAsync(
input,
isAdmin ? _userTypeaheadSearch : _orgMemberTypeaheadSearch,
[],
debounceMs);
function formatResult(user: SingleUserTypeaheadResult): string {
const extra = user.username && user.email ? ` (${user.username}, ${user.email})`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { BadgeButton } from '$lib/components/Badges';
import { DialogResponse, FormModal } from '$lib/components/modals';
import { Input, ProjectRoleSelect, isEmail } from '$lib/forms';
import { ProjectRoleSelect, isEmail } from '$lib/forms';
import { ProjectRole } from '$lib/gql/types';
import t from '$lib/i18n';
import { z } from 'zod';
Expand Down Expand Up @@ -77,24 +77,14 @@
{$t('project_page.add_user.modal_title')}
<SupHelp helpLink={helpLinks.addProjectMember} />
</span>
{#if $page.data.user?.isAdmin}
<UserTypeahead
id="usernameOrEmail"
label={$t('login.label_email')}
bind:value={$form.usernameOrEmail}
error={errors.usernameOrEmail}
autofocus
/>
{:else}
<Input
id="usernameOrEmail"
type="text"
label={$t('login.label_email')}
bind:value={$form.usernameOrEmail}
error={errors.usernameOrEmail}
autofocus
/>
{/if}
<UserTypeahead
id="usernameOrEmail"
isAdmin={$page.data.user?.isAdmin}
label={$t('login.label_email')}
bind:value={$form.usernameOrEmail}
error={errors.usernameOrEmail}
autofocus
/>
<ProjectRoleSelect bind:value={$form.role} error={errors.role} />
<svelte:fragment slot="extraActions">
<Checkbox
Expand Down

0 comments on commit ae71ccb

Please sign in to comment.