@supportworks/multi-imagepicker 7.3.2 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,269 +0,0 @@
1
- import React, { createContext, useCallback, useContext, useState } from 'react'
2
- import { View, StyleSheet, ScrollView, KeyboardAvoidingView, Pressable } from 'react-native'
3
- import { Icons } from '@supportworks/icon-library'
4
- import SelectedImages from './SelectedImages'
5
- import { colors } from '@supportworks/app-styler'
6
- import { LoadingOverlay } from '@supportworks/navbars'
7
- import { CheckBox, AppBarH8, CommonButton, ListItem, ScreenSafeAreaView } from '@supportworks/core-controls'
8
- import { Api } from '@supportworks/api-core'
9
- import UploadWarningModal from './UploadWarningModal'
10
-
11
- const AddImagesProviderContext = createContext(null)
12
-
13
- export const useAddImagesProvider = () => {
14
- const context = useContext(AddImagesProviderContext)
15
-
16
- if (!context) {
17
- throw new Error('AddImages must be used within an AddImagesProvider. See the ReadMe for examples, help and an AI prompt for your usage.')
18
- }
19
-
20
- return context
21
- }
22
-
23
- const SaveOptions = ({
24
- items = [],
25
- showToCustomerAllowed = false,
26
- allowSaveToDevice = false,
27
- onPressCheckboxShowToCust = null,
28
- onPressCheckboxSaveToDevice = null
29
- }) => {
30
- if (!showToCustomerAllowed && !allowSaveToDevice) {
31
- return null
32
- }
33
-
34
- const total = items.length
35
- const saveCount = items.filter(i => !!i.saveToDevice).length
36
- const showCount = items.filter(i => !!i.showToCust).length
37
- const allSave = total > 0 && saveCount === total
38
- const someSave = total > 0 && saveCount > 0 && saveCount < total
39
- const allShow = total > 0 && showCount === total
40
- const someShow = total > 0 && showCount > 0 && showCount < total
41
-
42
- return (
43
- <View style={styles.SaveOptionsContainer}>
44
- {showToCustomerAllowed
45
- ? <ListItem
46
- key='showToCust'
47
- leftContent={
48
- <View style={styles.IconCircle}>
49
- <Icons.IconEye_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
50
- </View>
51
- }
52
- mainAction={onPressCheckboxShowToCust}
53
- rightAction={onPressCheckboxShowToCust}
54
- title='Show all to customer'
55
- subtitle='Select to share all w/ customer.'
56
- rightContent={<CheckBox
57
- checked={allShow}
58
- indeterminate={someShow}
59
- onChange={onPressCheckboxShowToCust}
60
- />}
61
- height={55}
62
- paddingLeft={20}
63
- rightContentWidth={40}
64
- paddingRight={16}
65
- topSeparator={false}
66
- />
67
- : null}
68
- {allowSaveToDevice
69
- ? <ListItem
70
- key='saveToDevice'
71
- leftContent={
72
- <View style={styles.IconCircle}>
73
- <Icons.IconSave_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
74
- </View>
75
- }
76
- mainAction={onPressCheckboxSaveToDevice}
77
- rightAction={onPressCheckboxSaveToDevice}
78
- title='Download all to device'
79
- rightContent={<CheckBox
80
- checked={allSave}
81
- indeterminate={someSave}
82
- onChange={onPressCheckboxSaveToDevice}
83
- />}
84
- height={56}
85
- paddingLeft={20}
86
- rightContentWidth={40}
87
- paddingRight={16}
88
- topSeparator={showToCustomerAllowed}
89
- />
90
- : null}
91
- </View>
92
- )
93
- }
94
-
95
- const AddImagesEditor = ({ editorProps }) => {
96
- if (!editorProps) {
97
- return null
98
- }
99
-
100
- const {
101
- items = [],
102
- annotationAllowed = false,
103
- showToCustomerAllowed = false,
104
- allowSaveToDevice = false,
105
- allImageDataValid = true,
106
- showInfoDialog = false,
107
- onClose = null,
108
- onAttach = null,
109
- onDeleteItem = null,
110
- onItemChange = null,
111
- onCloseInfoDialog = null,
112
- onValidate = null,
113
- onPressCheckboxShowToCust = null,
114
- onPressCheckboxSaveToDevice = null
115
- } = editorProps
116
-
117
- return (
118
- <ScreenSafeAreaView style={styles.Page} edges={['top', 'bottom']} includeProvider>
119
- {/*<Pressable style={styles.KnobWrapper} onPress={onClose}>
120
- <View style={styles.Knob} />
121
- </Pressable>*/}
122
- <AppBarH8
123
- variant='regular'
124
- title='Photos to Add'
125
- subtitle={items.length + ' Photo' + (items.length > 1 ? 's' : '')}
126
- leftContentType='closeButton'
127
- callback={onClose}
128
- bgColor={colors.backgroundMedium}
129
- bottomShadow
130
- />
131
- <SaveOptions
132
- items={items}
133
- showToCustomerAllowed={showToCustomerAllowed}
134
- allowSaveToDevice={allowSaveToDevice}
135
- onPressCheckboxShowToCust={onPressCheckboxShowToCust}
136
- onPressCheckboxSaveToDevice={onPressCheckboxSaveToDevice}
137
- />
138
- <KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
139
- <ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
140
- <SelectedImages
141
- items={items}
142
- callback={onValidate}
143
- annotationAllowed={annotationAllowed}
144
- onDeleteItem={onDeleteItem}
145
- onItemChange={onItemChange}
146
- allowSaveToDevice={allowSaveToDevice}
147
- allowShowToCustomer={showToCustomerAllowed}
148
- />
149
- </ScrollView>
150
- </KeyboardAvoidingView>
151
- <View style={styles.ButtonContainer}>
152
- <CommonButton
153
- variant='filled'
154
- size='medium'
155
- fullWidth
156
- label='Attach'
157
- endIcon={<Icons.IconUploadAll />}
158
- onPress={onAttach}
159
- disabled={!allImageDataValid}
160
- />
161
- </View>
162
-
163
- {Api.getApi().sendPhotosToCRM() && (
164
- <UploadWarningModal
165
- visible={showInfoDialog}
166
- onClose={onCloseInfoDialog}
167
- />
168
- )}
169
- </ScreenSafeAreaView>
170
- )
171
- }
172
-
173
- const AddImagesProvider = ({ children, sheetTopInset = 0 }) => {
174
- const [editorState, setEditorState] = useState({
175
- visible: false,
176
- attaching: false,
177
- editorProps: null
178
- })
179
-
180
- const updateEditorState = useCallback((nextState) => {
181
- setEditorState({
182
- visible: !!nextState?.visible,
183
- attaching: !!nextState?.attaching,
184
- editorProps: nextState?.editorProps || null
185
- })
186
- }, [])
187
-
188
- return (
189
- <AddImagesProviderContext.Provider value={updateEditorState}>
190
- <View style={styles.ProviderContainer}>
191
- {children}
192
- {editorState.visible && (
193
- <View style={styles.Overlay}>
194
- <Pressable style={styles.Backdrop} onPress={editorState.editorProps?.onClose} />
195
- <View style={[styles.Sheet, { marginTop: sheetTopInset }]}>
196
- <AddImagesEditor editorProps={editorState.editorProps} />
197
- </View>
198
- </View>
199
- )}
200
- {editorState.attaching && <LoadingOverlay />}
201
- </View>
202
- </AddImagesProviderContext.Provider>
203
- )
204
- }
205
-
206
- const styles = StyleSheet.create({
207
- ProviderContainer: {
208
- flex: 1
209
- },
210
- Overlay: {
211
- ...StyleSheet.absoluteFillObject,
212
- justifyContent: 'flex-end',
213
- zIndex: 1000,
214
- elevation: 1000
215
- },
216
- Backdrop: {
217
- ...StyleSheet.absoluteFillObject,
218
- backgroundColor: 'rgba(0,0,0,0.45)'
219
- },
220
- Sheet: {
221
- flex: 1,
222
- borderTopLeftRadius: 16,
223
- borderTopRightRadius: 16,
224
- overflow: 'hidden'
225
- },
226
- Page: {
227
- backgroundColor: colors.backgroundMedium,
228
- flex: 1
229
- },
230
- KnobWrapper: {
231
- alignItems: 'center',
232
- paddingVertical: 9
233
- },
234
- Knob: {
235
- backgroundColor: colors.black18,
236
- borderRadius: 2,
237
- height: 4,
238
- width: 28
239
- },
240
- Content: {
241
- flex: 1
242
- },
243
- ScrollViewContainer: {
244
- paddingBottom: 100,
245
- marginTop: 8
246
- },
247
- SaveOptionsContainer: {
248
- backgroundColor: colors.white,
249
- margin: 16,
250
- borderRadius: 16
251
- },
252
- IconCircle: {
253
- width: 32,
254
- height: 32,
255
- borderRadius: 16,
256
- backgroundColor: colors.buttonPrimaryLight,
257
- justifyContent: 'center',
258
- alignItems: 'center'
259
- },
260
- ButtonContainer: {
261
- height: 56,
262
- paddingHorizontal: 16,
263
- paddingVertical: 8,
264
- borderTopWidth: 1,
265
- borderTopColor: colors.black05
266
- }
267
- })
268
-
269
- export default AddImagesProvider