@tryfinch/react-connect 3.1.0 → 3.1.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.
@@ -5,11 +5,11 @@
5
5
  "license": "MIT",
6
6
  "private": true,
7
7
  "dependencies": {
8
+ "@tryfinch/react-connect": "file:..",
8
9
  "@types/react": "^17.0.37",
9
10
  "prop-types": "^15.6.2",
10
11
  "react": "file:../node_modules/react",
11
- "react-dom": "^16.9.0",
12
- "react-finch-connect": "file:.."
12
+ "react-dom": "^16.9.0"
13
13
  },
14
14
  "scripts": {
15
15
  "start": "react-scripts start",
@@ -1,14 +1,49 @@
1
- .App {
1
+ .container {
2
2
  text-align: center;
3
- }
4
-
5
- .App-header {
6
3
  background-color: #282c34;
7
4
  min-height: 100vh;
8
5
  display: flex;
9
6
  flex-direction: column;
10
7
  align-items: center;
11
8
  justify-content: center;
12
- font-size: calc(10px + 2vmin);
9
+ font-size: calc(7px + 2vmin);
10
+ color: white;
11
+ }
12
+
13
+ a {
13
14
  color: white;
14
15
  }
16
+
17
+ .actions {
18
+ background-color: #4f4f4f;
19
+ padding: 1em;
20
+ border-radius: 10px;
21
+ margin: 1em 0;
22
+ }
23
+
24
+ .cta {
25
+ font-size: calc(7px + 2vmin);
26
+ padding: .5em;
27
+ }
28
+
29
+ .row {
30
+ margin: 2em 0;
31
+ }
32
+
33
+ .top-label {
34
+ display: block;
35
+ margin-bottom: .2em;
36
+ }
37
+
38
+ input[type=checkbox] {
39
+ width: 2em;
40
+ height: 2em;
41
+ }
42
+
43
+ .results {
44
+ background-color: #4f4f4f;
45
+ padding: 1em;
46
+ border-radius: 10px;
47
+ text-align: left;
48
+ margin: 1em 0;
49
+ }
@@ -1,32 +1,53 @@
1
1
  import React, { useState } from 'react';
2
- import { useFinchConnect, SuccessEvent, ErrorEvent } from 'react-finch-connect';
2
+ import { useFinchConnect, SuccessEvent, ErrorEvent } from '@tryfinch/react-connect';
3
+
4
+ import Result, { ResultContainer } from './Result';
5
+
3
6
  import './App.css';
4
7
 
5
8
  const App = () => {
6
- const [code, setCode] = useState<string>();
9
+ const [sendState, setSendState] = useState<boolean>(false);
10
+ const [result, setResult] = useState<ResultContainer>();
7
11
 
8
- const onSuccess = ({ code }: SuccessEvent) => setCode(code);
9
- const onError = ({ errorMessage }: ErrorEvent) => console.error(errorMessage);
10
- const onClose = () => console.log('User exited Finch Connect');
12
+ const onSuccess = (value: SuccessEvent) => setResult({ kind: 'success', value });
13
+ const onError = (value: ErrorEvent) => setResult({ kind: 'error', value });
14
+ const onClose = () => setResult({ kind: 'closed' });
11
15
 
12
16
  const { open } = useFinchConnect({
13
- clientId: '<your-client-id>',
17
+ clientId: 'c90b78c6-2151-4ca3-8fea-ccb708ffc5d9',
14
18
  products: ['company', 'directory', 'individual', 'employment'],
15
- // sandbox: false,
19
+ sandbox: true,
16
20
  // payrollProvider: '<payroll-provider-id>',
17
21
  onSuccess,
18
22
  onError,
19
23
  onClose,
20
24
  });
21
25
 
26
+ const submissionHandler: React.FormEventHandler<HTMLFormElement> = (e) => {
27
+ e.preventDefault();
28
+ open({
29
+ ...(sendState ? { state: new Date().toISOString() } : undefined),
30
+ })
31
+ };
32
+
22
33
  return (
23
- <div className="App">
24
- <header className="App-header">
25
- <p>Code: {code}</p>
26
- <button type="button" onClick={() => open()}>
27
- Open Finch Connect
28
- </button>
29
- </header>
34
+ <div className="container">
35
+ <h2><a href="https://www.npmjs.com/package/@tryfinch/react-connect">@tryfinch/react-connect</a> Example App</h2>
36
+ <form className="actions" onSubmit={submissionHandler}>
37
+ <div className="row">
38
+ <label className="top-label">Include State:</label>
39
+ <input type="checkbox" checked={sendState} onChange={() => setSendState(prev => !prev)} />
40
+ </div>
41
+ <div className="row">
42
+ <button className="cta" type="submit">
43
+ Open Finch Connect
44
+ </button>
45
+ </div>
46
+ </form>
47
+ <div className="results">
48
+ { !result && <p>Complete a Finch Connect session and the success event will be displayed here</p> }
49
+ { result && <Result result={result} /> }
50
+ </div>
30
51
  </div>
31
52
  );
32
53
  };
@@ -0,0 +1,26 @@
1
+ import { SuccessEvent, ErrorEvent } from '@tryfinch/react-connect';
2
+
3
+ export type ResultContainer = {
4
+ kind: 'success';
5
+ value: SuccessEvent;
6
+ } | {
7
+ kind: 'error';
8
+ value: ErrorEvent;
9
+ } | {
10
+ kind: 'closed',
11
+ };
12
+
13
+ const Result = ({ result }: { result: ResultContainer }) => {
14
+ if (result.kind === 'closed') {
15
+ return <>
16
+ <p>Closed!</p>
17
+ </>;
18
+ }
19
+
20
+ return <>
21
+ <p>{ result.kind === 'error' ? 'Error' : 'Success' }:</p>
22
+ <pre>{ JSON.stringify(result.value, null, 2) }</pre>
23
+ </>;
24
+ };
25
+
26
+ export default Result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryfinch/react-connect",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Finch SDK for embedding Finch Connect in API React Single Page Applications (SPA)",
5
5
  "keywords": [
6
6
  "finch",
package/src/index.ts CHANGED
@@ -23,7 +23,7 @@ export type ConnectOptions = {
23
23
  zIndex: number;
24
24
  };
25
25
 
26
- type OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products'>>) => void;
26
+ type OpenFn = (overrides?: Partial<Pick<ConnectOptions, 'products' | 'state'>>) => void;
27
27
 
28
28
  const POST_MESSAGE_NAME = 'finch-auth-message' as const;
29
29