Skip to content

Commit e294f99

Browse files
authored
Feature/change event name on success to on upload done (#106)
* feat(event): change name event onSuccess to onUploadDone * docs(event): @deprecated onSuccess, add onUploadDone
1 parent b9c71b9 commit e294f99

File tree

7 files changed

+24
-5
lines changed

7 files changed

+24
-5
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
- [Examples](#examples)
2626
- [filestack-js Client](#filestack-js-client)
2727
- [SSR](#ssr)
28-
- [Migration from 1.x.x and 2.x.x](#migration-from-1.x.x-and-2.x.x)
28+
- [Migration from 3.x.x and 4.x.x](#migration-from-3xx-and-4xx)
29+
- [Migration from 1.x.x and 2.x.x](#migration-from-1xx-and-2xx)
2930
- [Live demo](#live-demo)
3031
- [Development](#development)
3132
- [Documentation](#documentation)
32-
- [Contributing](#contributing)
33+
- [Contribution](#contribution)
3334
- [Future](#future)
3435

3536
## Overview
@@ -47,6 +48,7 @@ import { PickerOverlay } from 'filestack-react';
4748
<PickerOverlay
4849
apikey={YOUR_API_KEY}
4950
onSuccess={(res) => console.log(res)}
51+
onUploadDone={(res) => console.log(res)}
5052
/>
5153
```
5254
### Props
@@ -55,7 +57,9 @@ import { PickerOverlay } from 'filestack-react';
5557
| apikey | String | true | | Filestack api key |
5658
| clientOptions | Object | false | | https://filestack.github.io/filestack-js/interfaces/clientoptions.html |
5759
| pickerOptions | Object | false | | https://filestack.github.io/filestack-js/interfaces/pickeroptions.html |
58-
| onSuccess | Function | false | result => console.log(result) | A function to be called after successful completed action |
60+
| @deprecated onSuccess | Function | false | result => console.log(result) | A function to be called after successful completed action |
61+
| onUploadDone | Function | false | result => console.log(result) | Called when all files have been uploaded |
62+
| onError | Function | false | error => console.error(error) | A function to be called when error occurs |
5963
| onError | Function | false | error => console.error(error) | A function to be called when error occurs |
6064

6165
### Examples

src/picker/picker-base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export const pickerPropTypes = {
55
pickerOptions: PropTypes.object,
66
clientOptions: PropTypes.object,
77
onSuccess: PropTypes.func,
8+
onUploadDone: PropTypes.func,
89
onError: PropTypes.func
910
};

src/picker/picker-drop-pane.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const PickerDropPane = ({
88
pickerOptions,
99
clientOptions,
1010
onSuccess,
11+
onUploadDone,
1112
onError,
1213
children
1314
}) => {
@@ -19,6 +20,7 @@ const PickerDropPane = ({
1920
},
2021
clientOptions,
2122
onSuccess,
23+
onUploadDone,
2224
onError
2325
});
2426

src/picker/picker-inline.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const PickerInline = ({
88
pickerOptions,
99
clientOptions,
1010
onSuccess,
11+
onUploadDone,
1112
onError,
1213
children
1314
}) => {
@@ -16,6 +17,7 @@ const PickerInline = ({
1617
pickerOptions: { displayMode: PickerDisplayMode.inline, ...pickerOptions },
1718
clientOptions,
1819
onSuccess,
20+
onUploadDone,
1921
onError
2022
});
2123

src/picker/picker-overlay.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const PickerOverlay = ({
88
pickerOptions,
99
clientOptions,
1010
onSuccess,
11+
onUploadDone,
1112
onError,
1213
children
1314
}) => {
@@ -16,6 +17,7 @@ const PickerOverlay = ({
1617
pickerOptions: { displayMode: PickerDisplayMode.overlay, ...pickerOptions },
1718
clientOptions,
1819
onSuccess,
20+
onUploadDone,
1921
onError
2022
});
2123

src/picker/use-picker.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ const usePicker = ({
88
pickerOptions = {},
99
clientOptions = {},
1010
onSuccess = console.log,
11+
onUploadDone = console.log,
1112
onError = console.error
1213
}) => {
1314
const _onError = (error) => {
1415
onError(error);
1516
};
1617

17-
const _onSuccess = (result) => {
18+
const _onUploadDone = (result) => {
1819
onSuccess(result);
20+
onUploadDone(result);
1921
};
2022

2123
const rootId = _generateRandomId();
2224
const containerId = _generateRandomId();
2325
const picker = filestack.Filestack(apikey, clientOptions).picker({
2426
rootId,
2527
container: `#${containerId}`,
26-
onUploadDone: _onSuccess,
28+
onUploadDone: _onUploadDone,
2729
...pickerOptions
2830
});
2931

src/picker/use-picker.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ describe('usePicker hook', () => {
3232
expect(onSuccess).toHaveBeenCalledTimes(1);
3333
});
3434

35+
it('should call passed onUploadDone function', async () => {
36+
const onUploadDone = jest.fn();
37+
renderHook(() => usePicker({ apikey: 'x', onUploadDone }));
38+
expect(onUploadDone).toHaveBeenCalledTimes(1);
39+
});
40+
3541
it('should call passed onError function', async () => {
3642
const onError = jest.fn();
3743
renderHook(() => usePicker({ apikey: 'x', onError }));

0 commit comments

Comments
 (0)