Skip to content

Commit 7970523

Browse files
committed
Member autocomplete
1 parent 3e27671 commit 7970523

File tree

18 files changed

+282
-10
lines changed

18 files changed

+282
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"moment": "^2.29.3",
4040
"moment-timezone": "^0.5.34",
4141
"prop-types": "^15.8.1",
42+
"qs": "^6.11.0",
4243
"rc-checkbox": "^2.3.2",
4344
"react": "^17.0.2",
4445
"react-apexcharts": "^1.4.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "../styles/variables/palette";
2+
3+
.memberSelect {
4+
color: $black-60;
5+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { FC, FocusEvent } from 'react'
2+
import { MultiValue, StylesConfig } from 'react-select'
3+
// tslint:disable-next-line: no-submodule-imports
4+
import AsyncSelect from 'react-select/async'
5+
6+
import { InputWrapper } from '../form/form-groups/form-input/input-wrapper'
7+
8+
import { membersAutocompete, MembersAutocompeteResult } from './input-handle-functions'
9+
import styles from './InputHandleAutocomplete.module.scss'
10+
11+
export interface InputHandleAutocompleteProps {
12+
readonly className?: string
13+
readonly dirty?: boolean
14+
readonly disabled?: boolean
15+
readonly error?: string
16+
readonly hideInlineErrors?: boolean
17+
readonly hint?: string
18+
readonly label?: string | JSX.Element
19+
readonly name: string
20+
readonly onBlur?: (event: FocusEvent<HTMLInputElement>) => void
21+
readonly onChange: (newValue: Array<MembersAutocompeteResult>) => void
22+
readonly placeholder?: string
23+
readonly tabIndex: number
24+
readonly value?: Array<MembersAutocompeteResult>
25+
}
26+
27+
const InputHandleAutocomplete: FC<InputHandleAutocompleteProps> = (props: InputHandleAutocompleteProps) => {
28+
const customStyles: StylesConfig<any> = {
29+
control: (provided) => ({
30+
...provided,
31+
border: 'none',
32+
}),
33+
input: (provided) => ({
34+
...provided,
35+
color: 'inherit',
36+
fontSize: 16,
37+
}),
38+
multiValue: (provided) => ({
39+
...provided,
40+
borderRadius: 50,
41+
}),
42+
multiValueLabel: (provided) => ({
43+
...provided,
44+
fontSize: 12,
45+
}),
46+
option: (provided) => ({
47+
...provided,
48+
borderBottom: '1px solid #E9E9E9',
49+
color: 'inherit',
50+
fontSize: 16,
51+
fontWeight: 400,
52+
padding: 16,
53+
}),
54+
placeholder: (provided) => ({
55+
...provided,
56+
color: 'inherit',
57+
fontSize: 16,
58+
fontWeight: 400,
59+
}),
60+
valueContainer: (provided) => ({
61+
...provided,
62+
padding: 0,
63+
}),
64+
}
65+
66+
return (
67+
<InputWrapper
68+
{...props}
69+
dirty={!!props.dirty}
70+
disabled={!!props.disabled}
71+
label={props.label || props.name}
72+
hideInlineErrors={props.hideInlineErrors}
73+
type='text'
74+
>
75+
<AsyncSelect
76+
className={styles.memberSelect}
77+
cacheOptions
78+
getOptionLabel={({ handle }) => handle}
79+
getOptionValue={({ userId }) => userId}
80+
isMulti
81+
key={props.value?.length}
82+
loadOptions={membersAutocompete}
83+
styles={customStyles}
84+
placeholder={props.placeholder}
85+
onBlur={props.onBlur}
86+
onChange={(newValue: MultiValue<MembersAutocompeteResult>) => props.onChange(newValue as Array<MembersAutocompeteResult>)}
87+
value={props.value}
88+
isDisabled={props.disabled}
89+
/>
90+
</InputWrapper>
91+
)
92+
}
93+
94+
export default InputHandleAutocomplete
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as InputHandleAutocomplete } from './InputHandleAutocomplete'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import qs from 'qs'
2+
3+
import { xhrGetAsync } from '..'
4+
import { EnvironmentConfig } from '../../config'
5+
6+
export interface MembersAutocompeteQuery {
7+
term: string
8+
}
9+
10+
export interface MembersAutocompeteResult {
11+
firstName: string
12+
handle: string
13+
lastName: string
14+
userId: string
15+
}
16+
17+
export async function membersAutocompete(term: string): Promise<Array<MembersAutocompeteResult>> {
18+
const query: MembersAutocompeteQuery = {
19+
term,
20+
}
21+
22+
return xhrGetAsync(`${EnvironmentConfig.API.V5}/members/autocomplete?${qs.stringify(query)}`)
23+
}

src-ts/tools/gamification-admin/game-lib/game-badge.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ export interface GameBadge {
66
badge_name: string
77
badge_status: string
88
id: string
9+
member_badges?: Array<{
10+
awarded_at: string,
11+
awarded_by: string,
12+
user_handle: string,
13+
user_id: string,
14+
}>
915
organization_id: string
1016
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.tabWrap {
2+
display: flex;
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { FC } from 'react'
2+
3+
import { GameBadge } from '../../../game-lib'
4+
5+
import styles from './AwardedMembersTab.module.scss'
6+
7+
export interface AwardedMembersTabProps {
8+
awardedMembers?: GameBadge['member_badges']
9+
}
10+
11+
const AwardedMembersTab: FC<AwardedMembersTabProps> = (props: AwardedMembersTabProps) => {
12+
return (
13+
<div className={styles.tabWrap}>
14+
15+
</div>
16+
)
17+
}
18+
19+
export default AwardedMembersTab
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './AwardedMembersTab'

src-ts/tools/gamification-admin/pages/badge-detail/BadgeDetailPage.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,12 @@ $badgePreviewImage: 72px;
131131
}
132132
}
133133
}
134+
135+
.activeTabElement {
136+
margin-top: $space-xxxxl;
137+
138+
@include ltemd {
139+
margin-top: $space-md;
140+
}
141+
}
134142
}

0 commit comments

Comments
 (0)