Skip to content

Commit 5964412

Browse files
Implement plugin logic in campaign settings
The plugin integration logic has been implemented within the campaign settings. Users can now toggle between code integration and CMS plugins (WordPress/Shopify) for each campaign. The `IntegrationTypeSelector`, `CodeIntegration`, and `PluginIntegration` components are in place to manage these settings.
1 parent 22ea1d9 commit 5964412

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

api/shopify-config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Proxy pour les Firebase Functions depuis Vercel
2+
export default async function handler(req, res) {
3+
if (req.method !== 'POST') {
4+
return res.status(405).json({ error: 'Method not allowed' });
5+
}
6+
7+
try {
8+
// Forward la requête vers Firebase Functions
9+
const firebaseUrl = 'https://us-central1-refspring-project.cloudfunctions.net/shopifyInstall';
10+
11+
const response = await fetch(firebaseUrl, {
12+
method: 'POST',
13+
headers: {
14+
'Content-Type': 'application/json',
15+
},
16+
body: JSON.stringify(req.body)
17+
});
18+
19+
const data = await response.json();
20+
21+
if (!response.ok) {
22+
return res.status(response.status).json(data);
23+
}
24+
25+
res.json(data);
26+
} catch (error) {
27+
console.error('Proxy error:', error);
28+
res.status(500).json({ error: 'Internal server error' });
29+
}
30+
}

src/components/campaign-integration/PluginIntegration.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,39 @@ export const PluginIntegration: React.FC<PluginIntegrationProps> = ({ campaignId
153153

154154
setIsLoading(true);
155155
try {
156-
const state = btoa(JSON.stringify({ campaignId, userId, apiKey }));
157-
const shopifyUrl = `https://${shopifyShop}.myshopify.com/admin/oauth/authorize?client_id=YOUR_SHOPIFY_APP_ID&scope=read_orders,write_script_tags&redirect_uri=https://refspring.com/shopify/callback&state=${state}`;
158-
159-
window.open(shopifyUrl, '_blank');
156+
const response = await fetch('/api/shopify-config', {
157+
method: 'POST',
158+
headers: {
159+
'Content-Type': 'application/json',
160+
},
161+
body: JSON.stringify({
162+
shop: shopifyShop,
163+
code: 'oauth_code_placeholder',
164+
state: btoa(JSON.stringify({ campaignId, userId, apiKey })),
165+
campaignId
166+
})
167+
});
168+
169+
if (!response.ok) {
170+
throw new Error('Shopify configuration failed');
171+
}
172+
173+
const result = await response.json();
160174

161175
const newConfig: PluginConfig = {
162-
id: 'shopify_' + Date.now(),
176+
id: result.pluginId,
163177
type: 'shopify',
164178
domain: shopifyShop + '.myshopify.com',
165-
active: false,
179+
active: true,
166180
createdAt: new Date()
167181
};
168182

169183
setConfigs([...configs, newConfig]);
170184
setShopifyShop('');
171185

172186
toast({
173-
title: "Redirection Shopify",
174-
description: "Autorisez l'application dans la nouvelle fenêtre pour terminer l'installation",
187+
title: "Shopify configuré",
188+
description: "L'application Shopify a été installée avec succès",
175189
});
176190
} catch (error) {
177191
console.error('Erreur configuration Shopify:', error);

0 commit comments

Comments
 (0)