Skip to content

Commit 5295b01

Browse files
authored
Refactor note input fields to use TextArea component (tetherto#438)
1 parent 651a141 commit 5295b01

3 files changed

Lines changed: 69 additions & 77 deletions

File tree

package-lock.json

Lines changed: 16 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/screens/CreateRecord/CreateOrEditNoteContent.tsx

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import { useLingui } from '@lingui/react/macro'
22
import { useNavigation } from '@react-navigation/native'
33
import { useForm } from '@tetherto/pear-apps-lib-ui-react-hooks'
44
import { Validator } from '@tetherto/pear-apps-utils-validator'
5-
import { RECORD_TYPES, useCreateRecord, useRecords } from '@tetherto/pearpass-lib-vault'
5+
import {
6+
RECORD_TYPES,
7+
useCreateRecord,
8+
useRecords
9+
} from '@tetherto/pearpass-lib-vault'
610
import {
711
Button,
812
InputField,
913
MultiSlotInput,
1014
PasswordField,
1115
Text,
16+
TextArea,
1217
rawTokens,
1318
useTheme
1419
} from '@tetherto/pearpass-lib-ui-kit'
15-
import {
16-
Add,
17-
TrashOutlined
18-
} from '@tetherto/pearpass-lib-ui-kit/icons'
20+
import { Add, TrashOutlined } from '@tetherto/pearpass-lib-ui-kit/icons'
1921
import { StyleSheet, View } from 'react-native'
2022
import Toast from 'react-native-toast-message'
2123

@@ -111,15 +113,15 @@ export const CreateOrEditNoteContent = ({
111113

112114
const { handleSubmit, registerArray, values, setValue, errors } =
113115
useForm<FormValues>({
114-
initialValues: {
115-
title: initialRecord?.data?.title ?? '',
116-
note: initialRecord?.data?.note ?? '',
117-
customFields: initialRecord?.data?.customFields ?? [],
118-
folder: selectedFolder ?? initialRecord?.folder ?? '',
119-
attachments: initialRecord?.attachments ?? []
120-
},
121-
validate: (formValues) => schema.validate(formValues)
122-
})
116+
initialValues: {
117+
title: initialRecord?.data?.title ?? '',
118+
note: initialRecord?.data?.note ?? '',
119+
customFields: initialRecord?.data?.customFields ?? [],
120+
folder: selectedFolder ?? initialRecord?.folder ?? '',
121+
attachments: initialRecord?.attachments ?? []
122+
},
123+
validate: (formValues) => schema.validate(formValues)
124+
})
123125

124126
useGetMultipleFiles({
125127
fieldNames: ['attachments'],
@@ -158,7 +160,9 @@ export const CreateOrEditNoteContent = ({
158160
data: {
159161
title: formValues.title,
160162
note: formValues.note,
161-
customFields: formValues.customFields.filter((f) => f.note?.trim().length),
163+
customFields: formValues.customFields.filter(
164+
(f) => f.note?.trim().length
165+
),
162166
attachments: convertBase64FilesToUint8(
163167
formValues.attachments.filter(isUploadedNoteAttachment)
164168
)
@@ -189,7 +193,10 @@ export const CreateOrEditNoteContent = ({
189193
setValue('attachments', [...values.attachments, file])
190194
}
191195

192-
const handleAttachmentReplace = (index: number, file?: NoteAttachment | null) => {
196+
const handleAttachmentReplace = (
197+
index: number,
198+
file?: NoteAttachment | null
199+
) => {
193200
if (!file) {
194201
return
195202
}
@@ -246,11 +253,11 @@ export const CreateOrEditNoteContent = ({
246253
{t`Details`}
247254
</Text>
248255

249-
<InputField
256+
<TextArea
250257
label={t`Note`}
251258
value={values.note}
252259
placeholder={t`Enter Note`}
253-
onChangeText={(value) => setValue('note', value)}
260+
onChange={(value) => setValue('note', value)}
254261
testID="note-field"
255262
/>
256263
</View>
@@ -292,34 +299,32 @@ export const CreateOrEditNoteContent = ({
292299
testID="hidden-messages-multi-slot-input"
293300
>
294301
{customFieldsList.length ? (
295-
customFieldsList.map(
296-
(field, index) => (
297-
<PasswordField
298-
key={`${field.type}-${index}`}
299-
label={t`Hidden Message`}
300-
value={field.note ?? ''}
301-
placeholder={t`Enter Hidden Message`}
302-
onChangeText={(value) =>
303-
setValue(`customFields[${index}].note`, value)
304-
}
305-
isGrouped
306-
testID={`hidden-messages-multi-slot-input-slot-${index}`}
307-
rightSlot={
308-
customFieldsList.length > 1 ? (
309-
<Button
310-
size="small"
311-
variant="tertiary"
312-
aria-label="Delete hidden message"
313-
iconBefore={
314-
<TrashOutlined color={theme.colors.colorTextPrimary} />
315-
}
316-
onClick={() => removeCustomField(index)}
317-
/>
318-
) : undefined
319-
}
320-
/>
321-
)
322-
)
302+
customFieldsList.map((field, index) => (
303+
<PasswordField
304+
key={`${field.type}-${index}`}
305+
label={t`Hidden Message`}
306+
value={field.note ?? ''}
307+
placeholder={t`Enter Hidden Message`}
308+
onChangeText={(value) =>
309+
setValue(`customFields[${index}].note`, value)
310+
}
311+
isGrouped
312+
testID={`hidden-messages-multi-slot-input-slot-${index}`}
313+
rightSlot={
314+
customFieldsList.length > 1 ? (
315+
<Button
316+
size="small"
317+
variant="tertiary"
318+
aria-label="Delete hidden message"
319+
iconBefore={
320+
<TrashOutlined color={theme.colors.colorTextPrimary} />
321+
}
322+
onClick={() => removeCustomField(index)}
323+
/>
324+
) : undefined
325+
}
326+
/>
327+
))
323328
) : (
324329
<PasswordField
325330
label={t`Hidden Message`}

src/screens/RecordDetails/NoteRecordDetailsForm.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { useNavigation } from '@react-navigation/native'
55
import { useForm } from '@tetherto/pear-apps-lib-ui-react-hooks'
66
import {
77
AttachmentField,
8-
InputField,
98
MultiSlotInput,
109
PasswordField,
1110
Text,
11+
TextArea,
1212
rawTokens,
1313
useTheme
1414
} from '@tetherto/pearpass-lib-ui-kit'
@@ -118,14 +118,13 @@ export const NoteRecordDetailsForm = ({
118118
</Text>
119119

120120
<MultiSlotInput testID="comments-multi-slot-input">
121-
<InputField
121+
<TextArea
122122
label={t`Note`}
123123
value={values.note}
124124
placeholder={t`Enter Note`}
125125
readOnly
126126
copyable
127127
onCopy={copyToClipboard}
128-
isGrouped
129128
testID="comments-multi-slot-input-slot-0"
130129
/>
131130
</MultiSlotInput>

0 commit comments

Comments
 (0)