@teamvortexsoftware/vortex-react-native 0.0.12 → 1.0.0

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.
Files changed (33) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1227 -11
  3. package/package.json +102 -18
  4. package/dist/components/ShareButtons.js +0 -170
  5. package/dist/hooks/useThemeStyles.js +0 -39
  6. package/dist/hooks/useVortexInvite.js +0 -279
  7. package/dist/index.js +0 -5
  8. package/dist/shared/InvitationResult.js +0 -2
  9. package/dist/shared/api.js +0 -90
  10. package/dist/tests/TestVortexInvite.js +0 -134
  11. package/dist/types/components/ShareButtons.d.ts +0 -27
  12. package/dist/types/components/ShareButtons.d.ts.map +0 -1
  13. package/dist/types/hooks/useThemeStyles.d.ts +0 -34
  14. package/dist/types/hooks/useThemeStyles.d.ts.map +0 -1
  15. package/dist/types/hooks/useVortexInvite.d.ts +0 -41
  16. package/dist/types/hooks/useVortexInvite.d.ts.map +0 -1
  17. package/dist/types/index.d.ts +0 -2
  18. package/dist/types/index.d.ts.map +0 -1
  19. package/dist/types/shared/InvitationResult.d.ts +0 -24
  20. package/dist/types/shared/InvitationResult.d.ts.map +0 -1
  21. package/dist/types/shared/api.d.ts +0 -14
  22. package/dist/types/shared/api.d.ts.map +0 -1
  23. package/dist/types/tests/TestVortexInvite.d.ts +0 -4
  24. package/dist/types/tests/TestVortexInvite.d.ts.map +0 -1
  25. package/dist/types/utils/formUtils.d.ts +0 -85
  26. package/dist/types/utils/formUtils.d.ts.map +0 -1
  27. package/dist/types/utils/themeUtils.d.ts +0 -35
  28. package/dist/types/utils/themeUtils.d.ts.map +0 -1
  29. package/dist/types/vortexInvite.d.ts +0 -25
  30. package/dist/types/vortexInvite.d.ts.map +0 -1
  31. package/dist/utils/formUtils.js +0 -174
  32. package/dist/utils/themeUtils.js +0 -55
  33. package/dist/vortexInvite.js +0 -172
package/package.json CHANGED
@@ -1,48 +1,132 @@
1
1
  {
2
2
  "name": "@teamvortexsoftware/vortex-react-native",
3
- "description": "",
3
+ "description": "Vortex React Native SDK",
4
4
  "author": "@teamvortexsoftware",
5
- "version": "0.0.12",
5
+ "license": "Apache-2.0",
6
+ "version": "1.0.0",
6
7
  "files": [
7
8
  "dist"
8
9
  ],
9
10
  "main": "./dist/index.js",
10
11
  "exports": {
11
12
  ".": {
13
+ "source": "./src/index.tsx",
14
+ "react-native": {
15
+ "development": "./src/index.tsx",
16
+ "default": "./dist/index.js"
17
+ },
12
18
  "import": "./dist/index.js",
13
19
  "require": "./dist/index.js",
14
20
  "types": "./dist/types/index.d.ts"
15
21
  },
16
- "./runtime": "./dist/index.js"
22
+ "./web": {
23
+ "source": "./src/index-web.tsx",
24
+ "import": "./dist/index-web.js",
25
+ "require": "./dist/index-web.js",
26
+ "types": "./dist/types/index-web.d.ts"
27
+ },
28
+ "./runtime": "./dist/index.js",
29
+ "./hooks/useInvitationFormLogic": {
30
+ "source": "./src/hooks/useInvitationFormLogic.ts",
31
+ "import": "./dist/hooks/useInvitationFormLogic.js",
32
+ "require": "./dist/hooks/useInvitationFormLogic.js",
33
+ "types": "./dist/types/hooks/useInvitationFormLogic.d.ts"
34
+ },
35
+ "./constants/mockData": {
36
+ "source": "./src/constants/mockData.ts",
37
+ "import": "./dist/constants/mockData.js",
38
+ "require": "./dist/constants/mockData.js",
39
+ "types": "./dist/types/constants/mockData.d.ts"
40
+ },
41
+ "./utils/contactUtils": {
42
+ "source": "./src/utils/contactUtils.ts",
43
+ "import": "./dist/utils/contactUtils.js",
44
+ "require": "./dist/utils/contactUtils.js",
45
+ "types": "./dist/types/utils/contactUtils.d.ts"
46
+ }
17
47
  },
18
48
  "types": "dist/types/index.d.ts",
19
49
  "react-native": "dist/index.js",
20
50
  "devDependencies": {
21
- "@eslint/js": "^9.24.0",
22
- "@types/react": "^19.0.10",
51
+ "@eslint/js": "9.39.2",
52
+ "@testing-library/jest-dom": "6.9.1",
53
+ "@testing-library/react": "16.3.1",
54
+ "@types/react": "19.2.7",
23
55
  "@types/react-native-vector-icons": "^6.4.18",
24
- "eslint": "^9.24.0",
56
+ "@vitest/coverage-v8": "4.0.18",
57
+ "eslint": "9.39.2",
25
58
  "eslint-plugin-react-native": "^4.1.0",
26
- "typescript": "5.8.3",
27
- "typescript-eslint": "^8.30.1",
28
- "@teamvortexsoftware/typescript-config": "0.0.0",
29
- "@teamvortexsoftware/eslint-config": "0.0.0"
59
+ "expo-haptics": "^15.0.7",
60
+ "jsdom": "^26.0.2",
61
+ "react": "19.2.3",
62
+ "react-dom": "19.2.3",
63
+ "react-native-web": "^0.19.13",
64
+ "rimraf": "6.1.2",
65
+ "typescript-eslint": "8.50.1",
66
+ "vite": "7.3.1",
67
+ "vitest": "4.0.18"
30
68
  },
31
69
  "dependencies": {
32
- "react-native-qrcode-svg": "^6.3.15",
33
- "react-native-svg": "^15.12.0",
34
70
  "react-native-uuid": "^2.0.3",
35
- "react-native-vector-icons": "^10.2.0",
36
- "@teamvortexsoftware/vortex-core": "0.0.1"
71
+ "react-native-vector-icons": "^10.2.0"
37
72
  },
38
73
  "peerDependencies": {
39
- "react": ">=19.0.0",
40
- "react-native": ">=0.79.0"
74
+ "@react-native-clipboard/clipboard": ">=1.16.2",
75
+ "@react-native-google-signin/google-signin": ">=16.0.0",
76
+ "expo-clipboard": ">=7.1.4",
77
+ "expo-haptics": ">=13.0.0",
78
+ "expo-linear-gradient": ">=12.0.0",
79
+ "expo-sharing": ">=13.0.0",
80
+ "react": "19.2.3",
81
+ "react-native": ">=0.79.0",
82
+ "react-native-linear-gradient": ">=2.6.0",
83
+ "react-native-qrcode-svg": ">=6.3.0",
84
+ "react-native-svg": ">=15.0.0",
85
+ "react-qr-code": ">=2.0.0"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "@react-native-clipboard/clipboard": {
89
+ "optional": true
90
+ },
91
+ "@react-native-google-signin/google-signin": {
92
+ "optional": true
93
+ },
94
+ "expo-clipboard": {
95
+ "optional": true
96
+ },
97
+ "expo-haptics": {
98
+ "optional": true
99
+ },
100
+ "expo-linear-gradient": {
101
+ "optional": true
102
+ },
103
+ "expo-sharing": {
104
+ "optional": true
105
+ },
106
+ "react-native-linear-gradient": {
107
+ "optional": true
108
+ },
109
+ "react-native-qrcode-svg": {
110
+ "optional": true
111
+ },
112
+ "react-native-svg": {
113
+ "optional": true
114
+ },
115
+ "react-qr-code": {
116
+ "optional": true
117
+ }
41
118
  },
42
119
  "scripts": {
43
- "build": "tsc",
120
+ "clean": "rimraf dist",
121
+ "build": "pnpm run clean && tsc",
122
+ "dev": "pnpm run clean && tsc -w --preserveWatchOutput",
44
123
  "prepublish": "pnpm run build",
124
+ "build:prod": "pnpm run clean && tsc",
125
+ "prepublish:prod": "mkdir -p dist.d/prod && cp -r dist dist.d/prod/ && cp ./LICENSE ./README.md dist.d/prod/ && jq 'del(.dependencies.\"@teamvortexsoftware/analytics-client\") | del(.dependencies.\"@teamvortexsoftware/vortex-shared-ui\") | del(.devDependencies.\"@teamvortexsoftware/vortex-types\") | del(.devDependencies.\"@teamvortexsoftware/eslint-config\") | del(.devDependencies.\"@teamvortexsoftware/typescript-config\") | del(.scripts.prepack)' ./package.json > ./dist.d/prod/package.json",
126
+ "publish:prod": "pnpm run prepublish:prod && pnpm publish --access public ./dist.d/prod",
45
127
  "lint": "eslint src/",
46
- "type-check": "tsc --noEmit"
128
+ "type-check": "tsc --noEmit",
129
+ "test": "vitest",
130
+ "test:ci": "vitest run --coverage"
47
131
  }
48
132
  }
@@ -1,170 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ShareButton = ShareButton;
40
- exports.ShareButtons = ShareButtons;
41
- const react_1 = __importStar(require("react"));
42
- const react_native_1 = require("react-native");
43
- const FontAwesome6_1 = __importDefault(require("react-native-vector-icons/FontAwesome6"));
44
- const react_native_qrcode_svg_1 = __importDefault(require("react-native-qrcode-svg"));
45
- function ShareButton({ iconName, label, onPress, themeColors, themeStyles }) {
46
- return (<react_native_1.View style={styles.shareButtonWrapper}>
47
- <react_native_1.Pressable style={[styles.shareButton, themeStyles.secondaryButton]} onPress={onPress}>
48
- <react_native_1.View style={styles.buttonContentContainer}>
49
- <FontAwesome6_1.default name={iconName} size={24} color={themeColors.secondaryButtonForeground}/>
50
- <react_native_1.Text style={[styles.shareButtonText, themeStyles.secondaryButtonText]}>{label}</react_native_1.Text>
51
- </react_native_1.View>
52
- </react_native_1.Pressable>
53
- </react_native_1.View>);
54
- }
55
- function ShareButtons({ has, themeColors, themeStyles, handleShareLink, handleCopyLink, shareableLink, }) {
56
- const [showQRCode, setShowQRCode] = (0, react_1.useState)(false);
57
- // Define button configurations
58
- const buttonConfigs = [
59
- {
60
- key: 'shareOptionsNativeShareSheet',
61
- iconName: 'share-nodes',
62
- label: 'Native Share',
63
- onPress: handleShareLink,
64
- isAvailable: has.shareOptionsNativeShareSheet,
65
- },
66
- {
67
- key: 'shareOptionsCopyLink',
68
- iconName: 'copy',
69
- label: 'Copy',
70
- onPress: handleCopyLink,
71
- isAvailable: true, // Always available when share is enabled
72
- isWithShowUrl: has.shareOptionsCopyLink, // Special handling only if specifically enabled
73
- },
74
- {
75
- key: 'shareOptionsQRCode',
76
- iconName: 'qrcode',
77
- label: 'QR Code',
78
- onPress: () => setShowQRCode(!showQRCode),
79
- isAvailable: has.shareOptionsQrCode,
80
- },
81
- {
82
- key: 'shareOptionsWhatsApp',
83
- iconName: 'whatsapp',
84
- label: 'WhatsApp',
85
- onPress: () => { },
86
- isAvailable: has.shareOptionsWhatsApp,
87
- },
88
- {
89
- key: 'shareOptionsSms',
90
- iconName: 'message',
91
- label: 'SMS',
92
- onPress: () => { },
93
- isAvailable: has.shareOptionsSms,
94
- },
95
- // Add more share options as needed
96
- // Example:
97
- // {
98
- // key: 'shareOptionsFacebookMessenger',
99
- // iconName: 'facebook-messenger',
100
- // label: 'Messenger',
101
- // onPress: () => {},
102
- // isAvailable: has.shareOptionsFacebookMessenger,
103
- // },
104
- ];
105
- return (<>
106
- {showQRCode && shareableLink && (<react_native_1.View style={styles.qrCodeContainer}>
107
- <react_native_qrcode_svg_1.default value={shareableLink} size={200} color={themeColors.containerForeground} backgroundColor={themeColors.containerBackground}/>
108
- </react_native_1.View>)}
109
- {buttonConfigs
110
- .filter((config) => config.isAvailable)
111
- .map((config) => config.isWithShowUrl && config.key === 'shareOptionsCopyLink' && shareableLink ? (<react_native_1.View key={config.key} style={styles.copyLinkContainer}>
112
- <react_native_1.TextInput style={[
113
- styles.linkInput,
114
- { color: themeColors.containerForeground, borderColor: themeColors.containerBorder },
115
- ]} value={shareableLink} editable={false}/>
116
- <react_native_1.Pressable style={[styles.copyButton, themeStyles.secondaryButton]} onPress={handleCopyLink}>
117
- <FontAwesome6_1.default name="copy" size={20} color={themeColors.secondaryButtonForeground}/>
118
- </react_native_1.Pressable>
119
- </react_native_1.View>) : (<ShareButton key={config.key} iconName={config.iconName} label={config.label} onPress={config.onPress} themeColors={themeColors} themeStyles={themeStyles}/>))}
120
- </>);
121
- }
122
- const styles = react_native_1.StyleSheet.create({
123
- shareButtonWrapper: {
124
- width: '48%',
125
- margin: 5,
126
- },
127
- shareButton: {
128
- flexDirection: 'row',
129
- alignItems: 'center',
130
- padding: 10,
131
- borderWidth: 1,
132
- borderRadius: 5,
133
- justifyContent: 'center',
134
- },
135
- buttonContentContainer: {
136
- flexDirection: 'row',
137
- alignItems: 'center',
138
- },
139
- shareButtonText: {
140
- marginLeft: 10,
141
- },
142
- qrCodeContainer: {
143
- width: '100%',
144
- alignItems: 'center',
145
- justifyContent: 'center',
146
- marginBottom: 20,
147
- padding: 10,
148
- },
149
- copyLinkContainer: {
150
- width: '100%',
151
- flexDirection: 'row',
152
- marginVertical: 5,
153
- alignItems: 'center',
154
- },
155
- linkInput: {
156
- flex: 1,
157
- borderWidth: 1,
158
- borderRadius: 5,
159
- padding: 10,
160
- marginRight: 5,
161
- },
162
- copyButton: {
163
- width: 44,
164
- height: 44,
165
- alignItems: 'center',
166
- justifyContent: 'center',
167
- borderWidth: 1,
168
- borderRadius: 5,
169
- },
170
- });
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useThemeStyles = useThemeStyles;
4
- const react_1 = require("react");
5
- /**
6
- * Hook to generate dynamic styles based on theme colors
7
- * @param themeColors The theme colors object
8
- * @returns Object containing styled components based on the theme
9
- */
10
- function useThemeStyles(themeColors) {
11
- const themeStyles = (0, react_1.useMemo)(() => ({
12
- primaryButton: {
13
- backgroundColor: themeColors.primaryButtonBackground,
14
- borderColor: themeColors.primaryButtonBorder,
15
- },
16
- primaryButtonText: {
17
- color: themeColors.primaryButtonForeground,
18
- },
19
- secondaryButton: {
20
- backgroundColor: themeColors.secondaryButtonBackground,
21
- borderColor: themeColors.secondaryButtonBorder,
22
- },
23
- secondaryButtonText: {
24
- color: themeColors.secondaryButtonForeground,
25
- },
26
- containerStyles: {
27
- backgroundColor: themeColors.containerBackground,
28
- },
29
- textStyles: {
30
- color: themeColors.containerForeground,
31
- },
32
- inputStyles: {
33
- borderColor: themeColors.containerBorder,
34
- color: themeColors.containerForeground,
35
- backgroundColor: themeColors.containerBackground,
36
- },
37
- }), [themeColors]);
38
- return themeStyles;
39
- }
@@ -1,279 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useVortexInvite = useVortexInvite;
16
- const react_1 = require("react");
17
- const react_native_1 = require("react-native");
18
- const api_1 = __importDefault(require("../shared/api"));
19
- const themeUtils_1 = require("../utils/themeUtils");
20
- const useThemeStyles_1 = require("./useThemeStyles");
21
- const react_native_uuid_1 = __importDefault(require("react-native-uuid"));
22
- const formUtils_1 = require("../utils/formUtils");
23
- function useVortexInvite({ widgetId, environmentId, vortexApiHost, isLoading = false, jwt, onSuccess, onError, }) {
24
- const vortexClient = (0, react_1.useMemo)(() => new api_1.default(vortexApiHost, react_native_uuid_1.default.v4()), [vortexApiHost]);
25
- const [widgetConfiguration, setWidgetConfiguration] = (0, react_1.useState)();
26
- const [error, setError] = (0, react_1.useState)(null);
27
- const [fetching, setFetching] = (0, react_1.useState)(isLoading);
28
- const [loading, setLoading] = (0, react_1.useState)(true);
29
- const [email, setEmail] = (0, react_1.useState)('');
30
- const [shareableLink, setShareableLink] = (0, react_1.useState)();
31
- const [inviteLoading, setInviteLoading] = (0, react_1.useState)(false);
32
- const [showSuccessMessage, setShowSuccessMessage] = (0, react_1.useState)(false);
33
- const opacity = new react_native_1.Animated.Value(0.3);
34
- // Extract theme colors and feature flags using utility functions
35
- const themeColors = (0, react_1.useMemo)(() => (0, themeUtils_1.extractThemeColors)(widgetConfiguration), [widgetConfiguration]);
36
- // Extract form configuration
37
- const formConfig = (0, react_1.useMemo)(() => (0, formUtils_1.extractFormConfiguration)(widgetConfiguration), [widgetConfiguration]);
38
- // Get base theme styles
39
- const baseThemeStyles = (0, useThemeStyles_1.useThemeStyles)(themeColors);
40
- // Merge theme styles with component-specific styles from form configuration
41
- const themeStyles = (0, react_1.useMemo)(() => (0, formUtils_1.mergeThemeAndComponentStyles)(baseThemeStyles, themeColors, formConfig), [baseThemeStyles, themeColors, formConfig]);
42
- const options = (0, react_1.useMemo)(() => {
43
- var _a;
44
- return ((_a = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _a === void 0 ? void 0 : _a.props) || {};
45
- }, [widgetConfiguration]);
46
- // Extract form layout information
47
- const formLayout = (0, react_1.useMemo)(() => ({
48
- emailPlaceholder: (0, formUtils_1.getEmailPlaceholder)(formConfig),
49
- submitButtonLabel: (0, formUtils_1.getSubmitButtonLabel)(formConfig),
50
- isGridLayout: (0, formUtils_1.hasGridLayout)(formConfig),
51
- hasSeparateColumns: (0, formUtils_1.hasEmailAndShareInSeparateColumns)(formConfig),
52
- formConfig,
53
- }), [formConfig]);
54
- const has = (0, react_1.useMemo)(() => {
55
- const flags = (0, themeUtils_1.extractFeatureFlags)(widgetConfiguration);
56
- console.log('[Vortex] Invite has', flags);
57
- return flags;
58
- }, [widgetConfiguration]);
59
- // Log the host only once when the hook mounts
60
- (0, react_1.useEffect)(() => {
61
- if (vortexApiHost.indexOf('localhost') > -1) {
62
- console.warn('[Vortex] Invite Using localhost as host');
63
- }
64
- }, [vortexApiHost]);
65
- // Loading animation effect
66
- (0, react_1.useEffect)(() => {
67
- const animation = react_native_1.Animated.loop(react_native_1.Animated.sequence([
68
- react_native_1.Animated.timing(opacity, {
69
- toValue: 1,
70
- duration: 1000,
71
- useNativeDriver: false,
72
- }),
73
- react_native_1.Animated.timing(opacity, {
74
- toValue: 0.3,
75
- duration: 1000,
76
- useNativeDriver: false,
77
- }),
78
- ]));
79
- animation.start();
80
- setTimeout(() => {
81
- setLoading(false);
82
- animation.stop();
83
- }, 2000);
84
- }, [opacity]);
85
- // Fetch widget configuration if needed
86
- (0, react_1.useEffect)(() => {
87
- // Case: If `widgetConfiguration` is already set, do nothing
88
- if (widgetConfiguration) {
89
- console.log('[Vortex] Invite Already has widgetConfiguration, skipping fetch');
90
- return;
91
- }
92
- if (!jwt) {
93
- console.log('[Vortex] Invite JWT is required');
94
- return;
95
- }
96
- const fetchData = () => __awaiter(this, void 0, void 0, function* () {
97
- var _a;
98
- console.log('[Vortex] Invite Fetching Data...');
99
- setFetching(true);
100
- setLoading(true);
101
- setError(null);
102
- try {
103
- const result = yield vortexClient.getWidgetConfiguration(widgetId, jwt, environmentId);
104
- if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.widgetConfiguration) {
105
- setWidgetConfiguration(result.data.widgetConfiguration);
106
- console.log('[Vortex] Invite Successfully fetched widgetConfiguration', JSON.stringify(result.data.widgetConfiguration));
107
- }
108
- else {
109
- const error = (result === null || result === void 0 ? void 0 : result.error) || 'No configuration data found.';
110
- console.error(`[Vortex] Invite ${error}`);
111
- throw new Error(error);
112
- }
113
- }
114
- catch (err) {
115
- if (err instanceof Error) {
116
- const fetchError = err;
117
- console.error('[Vortex] Invite Error Details:', {
118
- message: fetchError.message,
119
- status: fetchError.status || 'unknown',
120
- statusText: fetchError.statusText,
121
- body: fetchError.body,
122
- stack: fetchError.stack,
123
- });
124
- }
125
- console.error('[Vortex] Invite Error', err);
126
- setError({
127
- message: err.message || 'Something went wrong!',
128
- });
129
- }
130
- finally {
131
- setFetching(false);
132
- setLoading(false);
133
- }
134
- });
135
- fetchData();
136
- }, [widgetId, jwt, environmentId, vortexClient, widgetConfiguration]);
137
- const handleInviteClick = (contentTokens) => __awaiter(this, void 0, void 0, function* () {
138
- try {
139
- setInviteLoading(true);
140
- setShowSuccessMessage(false);
141
- if (!(widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id)) {
142
- console.log('[Vortex Invite] Widget configuration ID is required');
143
- return;
144
- }
145
- // const url = `${host}/api/v1/no-auth/components/widget-configuration/${widgetConfigurationId}/invite`; // TODO should we use options.widgetHost?.value ?
146
- console.log('[Vortex] Invite Sending invitation', {
147
- email,
148
- widgetId,
149
- environmentId,
150
- });
151
- if (!jwt) {
152
- throw new Error('[Vortex Invite] JWT is required');
153
- }
154
- const payload = Object.assign(Object.assign({}, contentTokens), { email: {
155
- value: email,
156
- type: 'email',
157
- } });
158
- const body = yield vortexClient.createInvite(jwt, widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id, environmentId, payload);
159
- console.log('[Vortex] Invite Response', body);
160
- if (onSuccess) {
161
- onSuccess({
162
- type: 'invite',
163
- data: 'Email invite sent',
164
- });
165
- }
166
- setShowSuccessMessage(true);
167
- // Auto-hide success message after 5 seconds
168
- setTimeout(() => {
169
- setShowSuccessMessage(false);
170
- }, 5000);
171
- return;
172
- }
173
- catch (error) {
174
- console.error('[Vortex]', error);
175
- if (onError) {
176
- onError(error instanceof Error ? error : new Error(String(error)), 'invite');
177
- }
178
- throw error; // Re-throw the error to be caught by the component
179
- }
180
- finally {
181
- setInviteLoading(false);
182
- }
183
- });
184
- const getShareableLink = () => {
185
- return vortexClient.getShareableLinkFormatted();
186
- };
187
- const getShareableInviteLink = () => __awaiter(this, void 0, void 0, function* () {
188
- // if (this.isLoading || !this.vortex) {
189
- // return;
190
- // }
191
- if (!jwt || !(widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.id) || !vortexClient) {
192
- return;
193
- }
194
- if (shareableLink) {
195
- return shareableLink;
196
- }
197
- const invite = yield vortexClient.createShareableInvite(jwt, widgetConfiguration.id, environmentId);
198
- if (!invite || !invite.data || !invite.data.invitation.id) {
199
- console.error('No shareable link found');
200
- onError === null || onError === void 0 ? void 0 : onError(new Error('No shareable link found'), 'share');
201
- // this.error = {
202
- // message: 'No sharable link found',
203
- // };
204
- // this.host.requestUpdate();
205
- return;
206
- }
207
- const link = `${vortexApiHost}/noauth/invite/${invite.data.invitation.id}`;
208
- console.log(`getShareableInviteLink: ${link}`);
209
- setShareableLink(link); // TODO - need to differentiate invite host vs api host even though they are the same for now)
210
- return link;
211
- });
212
- const handleShareLink = () => __awaiter(this, void 0, void 0, function* () {
213
- try {
214
- const shareableLink = yield getShareableInviteLink();
215
- if (!shareableLink) {
216
- throw new Error('No shareable link available');
217
- }
218
- yield react_native_1.Share.share({
219
- message: shareableLink,
220
- title: 'Share Invite Link',
221
- });
222
- console.log('[Vortex] handleShareLink', 'The invite link has been shared.');
223
- if (onSuccess) {
224
- onSuccess({
225
- type: 'share',
226
- data: 'Sharable link used',
227
- });
228
- }
229
- }
230
- catch (error) {
231
- console.error('[Vortex] Failed to share link:', error);
232
- if (onError) {
233
- onError(error instanceof Error ? error : new Error(String(error)), 'share');
234
- }
235
- }
236
- });
237
- const handleCopyLink = () => __awaiter(this, void 0, void 0, function* () {
238
- try {
239
- const shareableLink = yield getShareableInviteLink();
240
- if (!shareableLink) {
241
- throw new Error('No shareable link available');
242
- }
243
- yield react_native_1.Clipboard.setString(shareableLink);
244
- console.log('[Vortex] handleCopyLink', 'The invite link has been copied.');
245
- if (onSuccess) {
246
- onSuccess({
247
- type: 'share',
248
- data: 'Sharable copied',
249
- });
250
- }
251
- }
252
- catch (error) {
253
- console.error('[Vortex] Failed to copy link:', error);
254
- if (onError) {
255
- onError(error instanceof Error ? error : new Error(String(error)), 'share');
256
- }
257
- }
258
- });
259
- return {
260
- widgetConfiguration,
261
- error,
262
- fetching,
263
- loading,
264
- email,
265
- setEmail,
266
- opacity,
267
- themeColors,
268
- themeStyles,
269
- has,
270
- options,
271
- inviteLoading,
272
- showSuccessMessage,
273
- handleInviteClick,
274
- handleShareLink,
275
- handleCopyLink,
276
- getShareableLink,
277
- formLayout,
278
- };
279
- }
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VortexInvite = void 0;
4
- var vortexInvite_1 = require("./vortexInvite");
5
- Object.defineProperty(exports, "VortexInvite", { enumerable: true, get: function () { return vortexInvite_1.VortexInvite; } });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });