-
Notifications
You must be signed in to change notification settings - Fork 58
/
GiveDrawer.tsx
290 lines (276 loc) · 7.55 KB
/
GiveDrawer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { useEffect, useState } from 'react';
import { useQuery } from 'react-query';
import { ChevronDown, ChevronUp } from '../../icons/__generated';
import { Avatar, Box, Button, Flex, Text, TextArea, MarkdownPreview } from 'ui';
import { SaveState, SavingIndicator } from 'ui/SavingIndicator';
import { Contribution } from './Contribution';
import { ContributorButton } from './ContributorButton';
import { QUERY_KEY_ALLOCATE_CONTRIBUTIONS } from './EpochStatementDrawer';
import { GiveAllocator } from './GiveAllocator';
import { Gift, Member } from './index';
import { getContributionsForEpoch } from './queries';
type GiveDrawerProps = {
member: Member;
gift: Gift;
updateNote(gift: Gift): void;
adjustGift(recipientId: number, amount: number): void;
maxedOut: boolean;
start_date: Date;
end_date: Date;
selectedMemberIdx: number;
totalMembers: number;
nextMember(asc: boolean): void;
saveState: SaveState;
setNeedToSave(save: boolean): void;
noGivingAllowed: boolean;
updateTeammate(id: number, teammate: boolean): void;
};
// GiveDrawer is the focused modal drawer to give/note/view contributions for one member
export const GiveDrawer = ({
// show,
member,
gift,
updateNote,
adjustGift,
maxedOut,
start_date,
end_date,
selectedMemberIdx,
totalMembers,
nextMember,
saveState,
setNeedToSave,
noGivingAllowed,
updateTeammate,
}: GiveDrawerProps) => {
// fetch the contributions for this particular member
const { data: contributions, refetch } = useQuery(
[QUERY_KEY_ALLOCATE_CONTRIBUTIONS, member.id],
() =>
getContributionsForEpoch({
circleId: member.circle_id,
userId: member.id,
start_date,
end_date,
}),
{
enabled: !!member,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Infinity,
}
);
// note is the current state of the note
const [note, setNote] = useState(gift.note);
// update the note in the to level page state
const saveNote = (gift: Gift, note?: string) => {
updateNote({ ...gift, note: note });
};
// noteChanged schedules a save to the underlying state in the parent component, clearing any pending save
const noteChanged = (newNote: string) => {
setNote(newNote);
saveNote({ ...gift }, newNote);
};
useEffect(() => {
if (member) {
// on member change reload the contributions
refetch().then();
// reset the need to save indicator so it doesnt say 'Changes Saved' when
// it has already moved to 'Saved'.
if (saveState == 'saved') {
setNeedToSave(false);
}
}
}, [member]);
useEffect(() => {
setNote(gift.note);
}, [gift]);
const nextPrevCss = {
color: '$text',
padding: '0',
minHeight: '32px',
height: '32px',
width: '32px',
mr: '$sm',
borderRadius: '$2',
alignItems: 'center',
'> svg': {
mr: 0,
},
};
return (
<Box key={selectedMemberIdx} css={{ height: '100%', pt: '$md' }}>
<Flex>
<Button
color="white"
size="large"
css={nextPrevCss}
disabled={selectedMemberIdx == 0}
onClick={() => nextMember(false)}
>
<ChevronUp size="lg" />
</Button>
<Button
color="white"
css={nextPrevCss}
disabled={selectedMemberIdx == totalMembers - 1}
onClick={() => nextMember(true)}
>
<ChevronDown size="lg" />
</Button>
</Flex>
<Flex
css={{
pt: '$xl',
gap: '$md',
'@sm': {
flexDirection: 'column',
},
}}
>
<Flex
css={{
flexGrow: 1,
minWidth: 0,
}}
alignItems="center"
>
<Avatar
size="small"
name={member.name}
path={member.profile.avatar}
margin="none"
css={{ mr: '$sm' }}
/>
<Text ellipsis h3 semibold>
{member.name}
</Text>
</Flex>
<Flex
css={{
justifyContent: 'space-between',
gap: '$md',
'@sm': {
flexDirection: 'column-reverse',
alignItems: 'flex-start',
},
}}
alignItems="center"
>
<Flex
css={{
justifyContent: 'flex-start',
mr: '$lg',
ml: '0',
}}
>
<ContributorButton
member={member}
updateTeammate={updateTeammate}
/>
</Flex>
<Flex css={{ justifyContent: 'flex-end' }}>
<Box>
<GiveAllocator
disabled={noGivingAllowed}
adjustGift={adjustGift}
gift={gift}
inPanel={true}
maxedOut={maxedOut}
optedOut={member.non_receiver || member.fixed_non_receiver}
/>
</Box>
</Flex>
</Flex>
</Flex>
<Box css={{ mt: '$xl' }}>
<Box>
<Text inline semibold size="large" css={{ mr: '$xs' }}>
Leave a Note
</Text>
{/*<ApeInfoTooltip>*/}
{/* Want to leave better feedback? Check out Coordinape’s Guide to*/}
{/* Giving Feedback in Web3*/}
{/*</ApeInfoTooltip>*/}
</Box>
<TextArea
autoSize
css={{
backgroundColor: 'white',
width: '100%',
mt: '$xs',
mb: '$md',
fontSize: '$medium',
}}
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={true}
value={note ?? ''}
onChange={e => noteChanged(e.target.value)}
placeholder="Say thanks or give constructive feedback."
/>
<Flex alignItems="center" css={{ justifyContent: 'flex-end' }}>
<SavingIndicator
saveState={saveState}
retry={() => {
saveNote({ ...gift }, note);
}}
/>
</Flex>
</Box>
<Flex
column
css={{
borderTop: '0.5px solid $secondaryText',
mt: '$lg',
pt: '$lg',
gap: '$md',
}}
>
{member.bio && (
<Box>
<Text semibold size="large">
Epoch Statement
</Text>
<Box
css={{
mb: '$xs',
p: '$md $sm',
borderBottom: '1px solid $border',
}}
>
<MarkdownPreview source={member.bio} />
</Box>
</Box>
)}
<Flex column>
<Text semibold size="large">
Contributions
</Text>
<Box css={{ p: '$md $sm' }}>
{!contributions && (
// TODO: Better loading indicator here -g
<Box>Loading...</Box>
)}
{contributions &&
(contributions.length == 0 ? (
<>
<Box>
<Text inline color="neutral">
<Text semibold inline color="neutral">
{member.name}{' '}
</Text>
has no contributions recorded for this epoch
</Text>
</Box>
</>
) : (
contributions.map(c => (
<Contribution key={c.id} contribution={c} />
))
))}
</Box>
</Flex>
</Flex>
</Box>
);
};