avada-components-seoon 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.
- package/README.md +71 -0
- package/dist/commands/autoTranslate.cjs +240 -0
- package/dist/commands/autoTranslate.cjs.map +1 -0
- package/dist/commands/autoTranslate.d.cts +2 -0
- package/dist/commands/autoTranslate.d.cts.map +1 -0
- package/dist/components/CrossAppBanner/index.d.ts +5 -0
- package/dist/components/CrossAppBanner/index.d.ts.map +1 -0
- package/dist/components/CrossAppBanner/index.js +192 -0
- package/dist/components/CrossAppBanner/index.js.map +1 -0
- package/dist/components/CrossAppBanner/index.scss +47 -0
- package/dist/components/CrossAppBanner/types.d.ts +81 -0
- package/dist/components/CrossAppBanner/types.d.ts.map +1 -0
- package/dist/components/CrossAppBanner/types.js +14 -0
- package/dist/components/CrossAppBanner/types.js.map +1 -0
- package/dist/components/PageSpeed/index.d.ts +81 -0
- package/dist/components/PageSpeed/index.d.ts.map +1 -0
- package/dist/components/PageSpeed/index.js +152 -0
- package/dist/components/PageSpeed/index.js.map +1 -0
- package/dist/components/PageSpeed/index.scss +233 -0
- package/dist/config/constants.d.ts +24 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +50 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/helpers/api.d.ts +6 -0
- package/dist/helpers/api.d.ts.map +1 -0
- package/dist/helpers/api.js +22 -0
- package/dist/helpers/api.js.map +1 -0
- package/dist/helpers/formatFullTime.d.ts +8 -0
- package/dist/helpers/formatFullTime.d.ts.map +1 -0
- package/dist/helpers/formatFullTime.js +45 -0
- package/dist/helpers/formatFullTime.js.map +1 -0
- package/dist/helpers/getProxyEndPoint.d.ts +7 -0
- package/dist/helpers/getProxyEndPoint.d.ts.map +1 -0
- package/dist/helpers/getProxyEndPoint.js +66 -0
- package/dist/helpers/getProxyEndPoint.js.map +1 -0
- package/dist/hooks/api/useFetchApi.d.ts +38 -0
- package/dist/hooks/api/useFetchApi.d.ts.map +1 -0
- package/dist/hooks/api/useFetchApi.js +74 -0
- package/dist/hooks/api/useFetchApi.js.map +1 -0
- package/dist/hooks/useI18n.d.ts +2 -0
- package/dist/hooks/useI18n.d.ts.map +1 -0
- package/dist/hooks/useI18n.js +35 -0
- package/dist/hooks/useI18n.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/da.json +38 -0
- package/dist/locales/de.json +38 -0
- package/dist/locales/en.json +38 -0
- package/dist/locales/es.json +38 -0
- package/dist/locales/fr.json +38 -0
- package/dist/locales/index.d.ts +383 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +23 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/nl.json +38 -0
- package/dist/locales/pt.json +38 -0
- package/dist/locales/sv.json +38 -0
- package/dist/locales/vi.json +38 -0
- package/dist/locales/zh-CN.json +38 -0
- package/dist/types/shop.d.ts +188 -0
- package/dist/types/shop.d.ts.map +1 -0
- package/dist/types/shop.js +5 -0
- package/dist/types/shop.js.map +1 -0
- package/package.json +91 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Avada Components
|
|
2
|
+
|
|
3
|
+
A collection of React components built with Shopify Polaris for company-wide app usage.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using yarn
|
|
9
|
+
yarn add avada-components
|
|
10
|
+
|
|
11
|
+
# Using npm
|
|
12
|
+
npm install avada-components
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Components
|
|
16
|
+
|
|
17
|
+
### SeoScore
|
|
18
|
+
|
|
19
|
+
A component for displaying SEO performance metrics and issues for a Shopify store.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { SeoScore } from 'avada-components';
|
|
23
|
+
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<SeoScore
|
|
27
|
+
type="widget" // or "banner"
|
|
28
|
+
shop={{
|
|
29
|
+
shopifyDomain: 'my-store.myshopify.com',
|
|
30
|
+
// other shop properties...
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Props
|
|
38
|
+
|
|
39
|
+
| Prop | Type | Required | Default | Description |
|
|
40
|
+
| ---- | ---------------------- | -------- | ---------- | ------------------------------ |
|
|
41
|
+
| type | `'widget' \| 'banner'` | No | `'widget'` | Display style of the SEO score |
|
|
42
|
+
| shop | `Shop` | Yes | - | Shop information object |
|
|
43
|
+
|
|
44
|
+
## TypeScript Support
|
|
45
|
+
|
|
46
|
+
This package is written in TypeScript and includes type definitions. You'll get full type support when using the components:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { SeoScore, type SeoScoreProps } from 'avada-components';
|
|
50
|
+
|
|
51
|
+
// Props will be type-checked
|
|
52
|
+
const props: SeoScoreProps = {
|
|
53
|
+
type: 'widget',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function App() {
|
|
57
|
+
return <SeoScore {...props} />;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
1. Fork the repository
|
|
64
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
65
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
66
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
67
|
+
5. Open a Pull Request
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
ISC
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const readline = require('readline');
|
|
5
|
+
const { v2 } = require('@google-cloud/translate');
|
|
6
|
+
const translate = new v2.Translate({ key: 'AIzaSyAwYJKHbjbj-eByPebF0RIfUi7YQjhxqyY' });
|
|
7
|
+
const rl = readline.createInterface({
|
|
8
|
+
input: process.stdin,
|
|
9
|
+
output: process.stdout,
|
|
10
|
+
});
|
|
11
|
+
const question = query => new Promise(resolve => rl.question(query, resolve));
|
|
12
|
+
const languages = [
|
|
13
|
+
{ code: 'nl', name: 'Dutch' },
|
|
14
|
+
{ code: 'vi', name: 'Vietnamese' },
|
|
15
|
+
{ code: 'pt-BR', name: 'Portuguese (Brazil)' },
|
|
16
|
+
{ code: 'fr', name: 'French' },
|
|
17
|
+
{ code: 'de', name: 'German' },
|
|
18
|
+
{ code: 'zh-CN', name: 'Chinese (Simplified)' },
|
|
19
|
+
{ code: 'es', name: 'Spanish' },
|
|
20
|
+
{ code: 'sv', name: 'Swedish' },
|
|
21
|
+
{ code: 'da', name: 'Danish' },
|
|
22
|
+
];
|
|
23
|
+
const protectPlaceholders = text => {
|
|
24
|
+
return text.replace(/\{([^}]+)\}/g, 'PLACEHOLDER_$1_PLACEHOLDER');
|
|
25
|
+
};
|
|
26
|
+
const restorePlaceholders = text => {
|
|
27
|
+
return text.replace(/PLACEHOLDER_([^_]+)_PLACEHOLDER/g, '{$1}');
|
|
28
|
+
};
|
|
29
|
+
const translateText = async (text, targetLang) => {
|
|
30
|
+
try {
|
|
31
|
+
const protectedText = protectPlaceholders(text);
|
|
32
|
+
const [translation] = await translate.translate(protectedText, { to: targetLang });
|
|
33
|
+
const result = restorePlaceholders(translation);
|
|
34
|
+
console.log(`Translated: "${text}" -> "${result}" (${targetLang})`);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Error translating text to ${targetLang}:`, error);
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const translateBatch = async (texts, targetLang) => {
|
|
43
|
+
try {
|
|
44
|
+
const protectedTexts = texts.map(text => protectPlaceholders(text));
|
|
45
|
+
const [translations] = await translate.translate(protectedTexts, { to: targetLang });
|
|
46
|
+
return translations.map((translation, index) => {
|
|
47
|
+
const result = restorePlaceholders(translation);
|
|
48
|
+
console.log(`Translated: "${texts[index]}" -> "${result}" (${targetLang})`);
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error(`Error translating batch to ${targetLang}:`, error);
|
|
54
|
+
return texts;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const translateObject = async (obj, targetLang, existingTranslations = {}) => {
|
|
58
|
+
const result = {};
|
|
59
|
+
const textsToTranslate = [];
|
|
60
|
+
const keysToTranslate = [];
|
|
61
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
if (existingTranslations[key] && existingTranslations[key] === value) {
|
|
64
|
+
result[key] = value;
|
|
65
|
+
console.log(`Skipped (already translated): "${value}" (${targetLang})`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
textsToTranslate.push(value);
|
|
69
|
+
keysToTranslate.push(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (typeof value === 'object' && value !== null) {
|
|
73
|
+
result[key] = await translateObject(value, targetLang, existingTranslations[key] || {});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result[key] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (textsToTranslate.length > 0) {
|
|
80
|
+
const translations = await translateBatch(textsToTranslate, targetLang);
|
|
81
|
+
keysToTranslate.forEach((key, index) => {
|
|
82
|
+
result[key] = translations[index];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
};
|
|
87
|
+
const findIndexJsonFiles = dir => {
|
|
88
|
+
const results = [];
|
|
89
|
+
const files = fs.readdirSync(dir);
|
|
90
|
+
for (const file of files) {
|
|
91
|
+
const fullPath = path.join(dir, file);
|
|
92
|
+
const stat = fs.statSync(fullPath);
|
|
93
|
+
if (stat.isDirectory()) {
|
|
94
|
+
results.push(...findIndexJsonFiles(fullPath));
|
|
95
|
+
}
|
|
96
|
+
else if (file === 'index.json') {
|
|
97
|
+
results.push({
|
|
98
|
+
path: fullPath,
|
|
99
|
+
folder: path.basename(path.dirname(fullPath)),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
};
|
|
105
|
+
const findChanges = (newData, oldData) => {
|
|
106
|
+
const changes = {};
|
|
107
|
+
for (const [key, value] of Object.entries(newData)) {
|
|
108
|
+
if (typeof value === 'string') {
|
|
109
|
+
if (!oldData[key] || oldData[key] !== value) {
|
|
110
|
+
changes[key] = value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (typeof value === 'object' && value !== null) {
|
|
114
|
+
const subChanges = findChanges(value, oldData[key] || {});
|
|
115
|
+
if (Object.keys(subChanges).length > 0) {
|
|
116
|
+
changes[key] = subChanges;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return changes;
|
|
121
|
+
};
|
|
122
|
+
const main = async () => {
|
|
123
|
+
try {
|
|
124
|
+
const srcDir = path.join(__dirname, '..');
|
|
125
|
+
const localesDir = path.join(srcDir, 'locales');
|
|
126
|
+
if (!fs.existsSync(localesDir)) {
|
|
127
|
+
fs.mkdirSync(localesDir, { recursive: true });
|
|
128
|
+
}
|
|
129
|
+
const indexFiles = findIndexJsonFiles(srcDir);
|
|
130
|
+
let totalWords = 0;
|
|
131
|
+
const translations = {};
|
|
132
|
+
const changes = {};
|
|
133
|
+
// Đọc dữ liệu cũ từ origin.json nếu có
|
|
134
|
+
let originData = {};
|
|
135
|
+
const originPath = path.join(localesDir, 'origin.json');
|
|
136
|
+
if (fs.existsSync(originPath)) {
|
|
137
|
+
try {
|
|
138
|
+
const originContent = JSON.parse(fs.readFileSync(originPath, 'utf8'));
|
|
139
|
+
originData = originContent.translation || {};
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('Error reading origin.json:', error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (const { path: filePath, folder } of indexFiles) {
|
|
146
|
+
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
147
|
+
translations[folder] = content;
|
|
148
|
+
const folderChanges = findChanges(content, originData[folder] || {});
|
|
149
|
+
if (Object.keys(folderChanges).length > 0) {
|
|
150
|
+
changes[folder] = folderChanges;
|
|
151
|
+
const wordCount = JSON.stringify(folderChanges).split(/\s+/).length;
|
|
152
|
+
totalWords += wordCount;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
console.log(`Total words to translate: ${totalWords}`);
|
|
156
|
+
console.log(`Estimated cost: $${(totalWords * 0.00002).toFixed(2)}`);
|
|
157
|
+
if (totalWords === 0) {
|
|
158
|
+
console.log('No changes detected. No translation needed.');
|
|
159
|
+
rl.close();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const proceed = await question('Do you want to proceed with translation? (y/n): ');
|
|
163
|
+
if (proceed.toLowerCase() !== 'y') {
|
|
164
|
+
console.log('Translation cancelled');
|
|
165
|
+
rl.close();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const pathTranslate = path.join(localesDir, 'en.json');
|
|
169
|
+
const pathOrigin = path.join(localesDir, 'origin.json');
|
|
170
|
+
fs.writeFileSync(pathTranslate, JSON.stringify({ translation: translations }, null, 2));
|
|
171
|
+
fs.writeFileSync(pathOrigin, JSON.stringify({ translation: translations }, null, 2));
|
|
172
|
+
for (const lang of languages) {
|
|
173
|
+
const targetLang = lang.code === 'pt-BR' ? 'pt' : lang.code;
|
|
174
|
+
console.log(`\nProcessing ${lang.name} (${targetLang})...`);
|
|
175
|
+
const outputPath = path.join(localesDir, `${targetLang}.json`);
|
|
176
|
+
let existingTranslations = {};
|
|
177
|
+
if (fs.existsSync(outputPath)) {
|
|
178
|
+
try {
|
|
179
|
+
const existingContent = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
|
180
|
+
existingTranslations = existingContent.translation || {};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error(`Error reading existing translations for ${targetLang}:`, error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const translatedData = {};
|
|
187
|
+
for (const [folder, content] of Object.entries(translations)) {
|
|
188
|
+
if (changes[folder]) {
|
|
189
|
+
const folderChanges = changes[folder];
|
|
190
|
+
const existingFolderData = existingTranslations[folder] || {};
|
|
191
|
+
const translatedChanges = await translateObject(folderChanges, targetLang, existingFolderData);
|
|
192
|
+
translatedData[folder] = {
|
|
193
|
+
...existingFolderData,
|
|
194
|
+
...translatedChanges,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
translatedData[folder] = existingTranslations[folder] || content;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
fs.writeFileSync(outputPath, JSON.stringify({ translation: translatedData }, null, 2));
|
|
202
|
+
console.log(`\nCompleted ${lang.name} translation`);
|
|
203
|
+
}
|
|
204
|
+
// Create/update index.ts file
|
|
205
|
+
const indexTsContent = `import en from './en.json';
|
|
206
|
+
import nl from './nl.json';
|
|
207
|
+
import zhCN from './zh-CN.json';
|
|
208
|
+
import vi from './vi.json';
|
|
209
|
+
import pt from './pt.json';
|
|
210
|
+
import sv from './sv.json';
|
|
211
|
+
import fr from './fr.json';
|
|
212
|
+
import de from './de.json';
|
|
213
|
+
import es from './es.json';
|
|
214
|
+
import da from './da.json';
|
|
215
|
+
|
|
216
|
+
export const translations = {
|
|
217
|
+
en,
|
|
218
|
+
nl,
|
|
219
|
+
'zh-CN': zhCN,
|
|
220
|
+
vi,
|
|
221
|
+
'pt-BR': pt,
|
|
222
|
+
sv,
|
|
223
|
+
fr,
|
|
224
|
+
de,
|
|
225
|
+
es,
|
|
226
|
+
da,
|
|
227
|
+
};
|
|
228
|
+
`;
|
|
229
|
+
fs.writeFileSync(path.join(localesDir, 'index.ts'), indexTsContent);
|
|
230
|
+
console.log('\nUpdated index.ts file');
|
|
231
|
+
console.log('\nTranslation completed successfully!');
|
|
232
|
+
rl.close();
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
console.error('Error:', error);
|
|
236
|
+
rl.close();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
main();
|
|
240
|
+
//# sourceMappingURL=autoTranslate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoTranslate.cjs","sourceRoot":"","sources":["../../src/commands/autoTranslate.cjs"],"names":[],"mappings":";AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAElD,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,yCAAyC,EAAE,CAAC,CAAC;AAEvF,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9E,MAAM,SAAS,GAAG;IAChB,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE;IAC7B,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE;IAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,E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autoTranslate.cjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CrossAppBanner/index.tsx"],"names":[],"mappings":"AAIA,OAAO,cAAc,CAAC;AAWtB,OAAO,EAKL,uBAAuB,EAExB,MAAM,SAAS,CAAC;AA8CjB,eAAO,MAAM,cAAc,EAAE,uBA4M5B,CAAC;AACF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AppProvider, Button, LegacyCard, Text, Thumbnail } from '@shopify/polaris';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
|
|
5
|
+
import './index.scss';
|
|
6
|
+
import { listCrossApps } from '../../config/constants';
|
|
7
|
+
import { getAppIdByOrigin, getCheckInstalledProxyUrl, getProxyAccessToken, } from '../../helpers/getProxyEndPoint';
|
|
8
|
+
import { XIcon } from '@shopify/polaris-icons';
|
|
9
|
+
import { isEmpty } from 'lodash';
|
|
10
|
+
import { APP_IDS, } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* CrossAppBanner Component
|
|
13
|
+
*
|
|
14
|
+
* A banner component that displays promotional content for other Avada apps.
|
|
15
|
+
* It checks the installation status of specified apps and shows the first non-installed app.
|
|
16
|
+
* Each app can be dismissed independently.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* // Basic usage
|
|
21
|
+
* <CrossAppBanner
|
|
22
|
+
* shopDomain="your-store.myshopify.com"
|
|
23
|
+
* />
|
|
24
|
+
*
|
|
25
|
+
* // With custom callbacks
|
|
26
|
+
* <CrossAppBanner
|
|
27
|
+
* shopDomain="your-store.myshopify.com"
|
|
28
|
+
* clickInstallCallback={() => console.log('Install clicked')}
|
|
29
|
+
* />
|
|
30
|
+
*
|
|
31
|
+
* // With specific apps to check
|
|
32
|
+
* <CrossAppBanner
|
|
33
|
+
* shopDomain="your-store.myshopify.com"
|
|
34
|
+
* appIds={['avada-seo-suite', 'ai-product-copy']}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param props - Component props
|
|
39
|
+
* @param props.shopDomain - The shop domain to check app installation status
|
|
40
|
+
* @param props.clickInstallCallback - Callback function when user clicks install button
|
|
41
|
+
* @param props.appIds - List of app IDs to check in priority order, current support 'avada-seo-suite', 'seoon-blog', 'ai-product-copy', 'ap-speed-optimizer'
|
|
42
|
+
* @returns JSX.Element | null
|
|
43
|
+
*/
|
|
44
|
+
const defaultQueryClient = new QueryClient({
|
|
45
|
+
defaultOptions: {
|
|
46
|
+
queries: {
|
|
47
|
+
staleTime: 25 * 60 * 1000,
|
|
48
|
+
gcTime: 30 * 60 * 1000,
|
|
49
|
+
retry: 2,
|
|
50
|
+
refetchOnWindowFocus: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export const CrossAppBanner = ({ shopDomain, clickInstallCallback, appIds = ['avada-seo-suite', 'seoon-blog', 'ai-product-copy', 'ap-speed-optimizer'], }) => {
|
|
55
|
+
const [isBannerDismissed, setIsBannerDismissed] = useState(false);
|
|
56
|
+
const [dismissedApps, setDismissedApps] = useState({
|
|
57
|
+
'avada-seo-suite': false,
|
|
58
|
+
'seoon-blog': false,
|
|
59
|
+
'ai-product-copy': false,
|
|
60
|
+
'ap-speed-optimizer': false,
|
|
61
|
+
});
|
|
62
|
+
const [currentPriorityIndex, setCurrentPriorityIndex] = useState(0);
|
|
63
|
+
const [installedApps, setInstalledApps] = useState({
|
|
64
|
+
seo: false,
|
|
65
|
+
blog: false,
|
|
66
|
+
aiCopy: false,
|
|
67
|
+
plaza: false,
|
|
68
|
+
});
|
|
69
|
+
const [foundNonInstalledApp, setFoundNonInstalledApp] = useState(false);
|
|
70
|
+
const getCurrentPagePath = () => {
|
|
71
|
+
const url = window.location.href;
|
|
72
|
+
const pathMatch = url.match(/https?:\/\/[^/]+(\/[^?]+)/);
|
|
73
|
+
return pathMatch ? pathMatch[1] : '';
|
|
74
|
+
};
|
|
75
|
+
const getStorageKey = (appId) => {
|
|
76
|
+
const pagePath = getCurrentPagePath();
|
|
77
|
+
const appOriginId = getAppIdByOrigin(window.location.origin);
|
|
78
|
+
return `cross-app-banner-dismissed-${appOriginId}-${pagePath}-${appId}`;
|
|
79
|
+
};
|
|
80
|
+
// Load dismissed apps from localStorage
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const loadDismissedApps = () => {
|
|
83
|
+
const dismissed = {
|
|
84
|
+
'avada-seo-suite': false,
|
|
85
|
+
'seoon-blog': false,
|
|
86
|
+
'ai-product-copy': false,
|
|
87
|
+
'ap-speed-optimizer': false,
|
|
88
|
+
};
|
|
89
|
+
appIds.forEach(appId => {
|
|
90
|
+
const storedDismissed = localStorage.getItem(getStorageKey(appId));
|
|
91
|
+
if (storedDismissed === 'true') {
|
|
92
|
+
dismissed[appId] = true;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
setDismissedApps(dismissed);
|
|
96
|
+
};
|
|
97
|
+
loadDismissedApps();
|
|
98
|
+
}, [appIds]);
|
|
99
|
+
// Get current app to check based on priority
|
|
100
|
+
const currentAppId = appIds[currentPriorityIndex];
|
|
101
|
+
const shouldCheckCurrentApp = currentAppId && !foundNonInstalledApp;
|
|
102
|
+
// API call function
|
|
103
|
+
const fetchAppInstallationStatus = async (appId) => {
|
|
104
|
+
const response = await fetch(getCheckInstalledProxyUrl(appId), {
|
|
105
|
+
headers: {
|
|
106
|
+
'X-SEO-Access-Token': getProxyAccessToken(appId),
|
|
107
|
+
'X-SEO-Shop-Domain': shopDomain,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok)
|
|
111
|
+
throw new Error('Failed to fetch app installation status');
|
|
112
|
+
const data = await response.json();
|
|
113
|
+
return {
|
|
114
|
+
...data,
|
|
115
|
+
appId,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
const { data, isLoading: loading, refetch: fetchApi, } = useQuery({
|
|
119
|
+
queryKey: ['appInstallation', currentAppId, shopDomain],
|
|
120
|
+
queryFn: () => fetchAppInstallationStatus(currentAppId),
|
|
121
|
+
enabled: false,
|
|
122
|
+
staleTime: 25 * 60 * 1000,
|
|
123
|
+
gcTime: 30 * 60 * 1000,
|
|
124
|
+
retry: 2,
|
|
125
|
+
refetchOnWindowFocus: false,
|
|
126
|
+
});
|
|
127
|
+
// Effect to check app installation
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (shouldCheckCurrentApp) {
|
|
130
|
+
const isDismissed = localStorage.getItem(getStorageKey(currentAppId)) === 'true';
|
|
131
|
+
if (!isDismissed) {
|
|
132
|
+
fetchApi();
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// If app is dismissed, move to next app
|
|
136
|
+
setCurrentPriorityIndex(prev => prev + 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}, [currentAppId, shouldCheckCurrentApp]);
|
|
140
|
+
// Effect to handle installation check result
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!isEmpty(data) && data.appId === currentAppId && shouldCheckCurrentApp) {
|
|
143
|
+
const newInstalledApps = { ...installedApps };
|
|
144
|
+
const isInstalled = currentAppId === 'avada-seo-suite' || currentAppId === 'seoon-blog'
|
|
145
|
+
? data.userType === 'user'
|
|
146
|
+
: !!data.isInstalled;
|
|
147
|
+
newInstalledApps[APP_IDS[currentAppId]] = isInstalled;
|
|
148
|
+
setInstalledApps(newInstalledApps);
|
|
149
|
+
if (isInstalled) {
|
|
150
|
+
setCurrentPriorityIndex(prev => prev + 1);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
setFoundNonInstalledApp(true);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, [data, currentAppId, shouldCheckCurrentApp]);
|
|
157
|
+
const handleDismiss = (appId) => {
|
|
158
|
+
localStorage.setItem(getStorageKey(appId), 'true');
|
|
159
|
+
setIsBannerDismissed(true);
|
|
160
|
+
};
|
|
161
|
+
const checking = loading;
|
|
162
|
+
// Find first non-installed app based on priority
|
|
163
|
+
const getFirstNonInstalledApp = () => {
|
|
164
|
+
if (isBannerDismissed)
|
|
165
|
+
return null;
|
|
166
|
+
if (appIds.length > 0) {
|
|
167
|
+
const priorityApp = appIds.find(appKey => {
|
|
168
|
+
const key = appKey;
|
|
169
|
+
return !installedApps[APP_IDS[key]] && !dismissedApps[key];
|
|
170
|
+
});
|
|
171
|
+
if (priorityApp) {
|
|
172
|
+
return listCrossApps.find(app => APP_IDS[priorityApp] === app.key);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// If no priority apps or all priority apps are installed, find first non-installed app from listCrossApps
|
|
176
|
+
return listCrossApps.find(app => {
|
|
177
|
+
const appId = Object.entries(APP_IDS).find(([_, value]) => value === app.key)?.[0];
|
|
178
|
+
return (!installedApps[app.key] && !dismissedApps[appId] && appIds.includes(appId));
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
const appToShow = getFirstNonInstalledApp();
|
|
182
|
+
if (checking || !appToShow || isBannerDismissed || isEmpty(data))
|
|
183
|
+
return null;
|
|
184
|
+
const currentAppIdToShow = Object.entries(APP_IDS).find(([_, value]) => value === appToShow.key)?.[0];
|
|
185
|
+
return (_jsx(AppProvider, { i18n: {}, children: _jsx(QueryClientProvider, { client: defaultQueryClient, children: _jsx(LegacyCard, { sectioned: true, children: _jsxs("div", { className: 'AC-CrossAppBanner', children: [_jsx("div", { className: 'AC-CrossAppBanner__Thumbnail', children: _jsx(Thumbnail, { size: "small", source: appToShow.image, alt: '' }) }), _jsxs("div", { className: 'AC-CrossAppBanner__Content', children: [_jsx(Text, { variant: "headingMd", as: "strong", children: appToShow.title }), _jsx("br", {}), appToShow.description] }), _jsx("div", { className: 'AC-CrossAppBanner__Install', children: _jsx(Button, { onClick: () => {
|
|
186
|
+
window.open(appToShow.url);
|
|
187
|
+
if (clickInstallCallback)
|
|
188
|
+
clickInstallCallback();
|
|
189
|
+
}, children: appToShow.actionLabel }) }), _jsx("div", { className: 'AC-CrossAppBanner__Close', children: _jsx(Button, { icon: XIcon, variant: "tertiary", onClick: () => handleDismiss(currentAppIdToShow) }) })] }) }) }) }));
|
|
190
|
+
};
|
|
191
|
+
export default CrossAppBanner;
|
|
192
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/CrossAppBanner/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEnF,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAML,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,kBAAkB,GAAG,IAAI,WAAW,CAAC;IACzC,cAAc,EAAE;QACd,OAAO,EAAE;YACP,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;YACzB,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;YACtB,KAAK,EAAE,CAAC;YAC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EAAE,4BAA4B,aAC1C,KAAC,IAAI,IAAC,OAAO,EAAC,WAAW,EAAC,EAAE,EAAC,QAAQ,YAClC,SAAS,CAAC,KAAK,GACX,EACP,cAAM,EACL,SAAS,CAAC,WAAW,IAClB,EACN,cAAK,SAAS,EAAE,4BAA4B,YAC1C,KAAC,MAAM,IACL,OAAO,EAAE,GAAG,EAAE;oCACZ,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;oCAC3B,IAAI,oBAAoB;wCAAE,oBAAoB,EAAE,CAAC;gCACnD,CAAC,YAEA,SAAS,CAAC,WAAW,GACf,GACL,EACN,cAAK,SAAS,EAAE,0BAA0B,YACxC,KAAC,MAAM,IACL,IAAI,EAAE,KAA4B,EAClC,OAAO,EAAC,UAAU,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAChD,GACE,IACF,GACK,GACO,GACV,CACf,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.AC-CrossAppBanner {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: flex;
|
|
4
|
+
gap: 16px;
|
|
5
|
+
align-items: center;
|
|
6
|
+
|
|
7
|
+
&.audit {
|
|
8
|
+
.AC-CrossAppBanner__Thumbnail {
|
|
9
|
+
max-width: 50px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.AC-CrossAppBanner__Close {
|
|
13
|
+
right: -2px;
|
|
14
|
+
top: -2px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.AC-CrossAppBanner__Install {
|
|
18
|
+
min-width: 150px;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.AC-CrossAppBanner__Thumbnail {
|
|
23
|
+
max-width: 70px;
|
|
24
|
+
border-radius: 8px;
|
|
25
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.AC-CrossAppBanner__Content {
|
|
30
|
+
flex: 1;
|
|
31
|
+
vertical-align: center;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.AC-CrossAppBanner__Install {
|
|
35
|
+
min-width: 120px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.AC-CrossAppBanner__Close {
|
|
39
|
+
position: absolute;
|
|
40
|
+
right: -6px;
|
|
41
|
+
top: -6px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@media screen and (max-width: 425px) {
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
}
|
|
47
|
+
}
|