|
@@ -6,6 +6,7 @@ import { Label } from "@/components/ui/label";
|
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
|
import { Loader2, Store, ExternalLink, CheckCircle2, AlertCircle, Shield } from "lucide-react";
|
|
import { Loader2, Store, ExternalLink, CheckCircle2, AlertCircle, Shield } from "lucide-react";
|
|
|
import { API_URL } from "@/lib/config";
|
|
import { API_URL } from "@/lib/config";
|
|
|
|
|
+import { PhoneNumberSelector } from "./PhoneNumberSelector";
|
|
|
|
|
|
|
|
interface ShopifyConnectProps {
|
|
interface ShopifyConnectProps {
|
|
|
onClose?: () => void;
|
|
onClose?: () => void;
|
|
@@ -13,12 +14,15 @@ interface ShopifyConnectProps {
|
|
|
|
|
|
|
|
export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
|
|
export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
|
|
|
const [shopDomain, setShopDomain] = useState("");
|
|
const [shopDomain, setShopDomain] = useState("");
|
|
|
|
|
+ const [phoneNumberId, setPhoneNumberId] = useState("");
|
|
|
const [isConnecting, setIsConnecting] = useState(false);
|
|
const [isConnecting, setIsConnecting] = useState(false);
|
|
|
const [error, setError] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
|
+ const [phoneNumberError, setPhoneNumberError] = useState("");
|
|
|
const [success, setSuccess] = useState(false);
|
|
const [success, setSuccess] = useState(false);
|
|
|
|
|
|
|
|
const handleConnect = async () => {
|
|
const handleConnect = async () => {
|
|
|
setError("");
|
|
setError("");
|
|
|
|
|
+ setPhoneNumberError("");
|
|
|
setSuccess(false);
|
|
setSuccess(false);
|
|
|
|
|
|
|
|
// Validate shop domain
|
|
// Validate shop domain
|
|
@@ -27,6 +31,13 @@ export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Validate phone number
|
|
|
|
|
+ if (!phoneNumberId) {
|
|
|
|
|
+ setPhoneNumberError("Please select a phone number for this store");
|
|
|
|
|
+ setError("Please select a phone number before connecting");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Normalize domain
|
|
// Normalize domain
|
|
|
let normalizedDomain = shopDomain.trim().toLowerCase();
|
|
let normalizedDomain = shopDomain.trim().toLowerCase();
|
|
|
|
|
|
|
@@ -63,9 +74,9 @@ export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
|
|
|
|
|
|
|
|
const session = JSON.parse(sessionData);
|
|
const session = JSON.parse(sessionData);
|
|
|
|
|
|
|
|
- // Call the OAuth initiation Edge Function
|
|
|
|
|
|
|
+ // Call the OAuth initiation Edge Function with phone_number_id
|
|
|
const response = await fetch(
|
|
const response = await fetch(
|
|
|
- `${API_URL}/oauth-shopify?action=init&shop=${encodeURIComponent(normalizedDomain)}`,
|
|
|
|
|
|
|
+ `${API_URL}/oauth-shopify?action=init&shop=${encodeURIComponent(normalizedDomain)}&phone_number_id=${encodeURIComponent(phoneNumberId)}`,
|
|
|
{
|
|
{
|
|
|
method: 'GET',
|
|
method: 'GET',
|
|
|
headers: {
|
|
headers: {
|
|
@@ -160,6 +171,13 @@ export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
|
|
|
</p>
|
|
</p>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ <PhoneNumberSelector
|
|
|
|
|
+ value={phoneNumberId}
|
|
|
|
|
+ onChange={setPhoneNumberId}
|
|
|
|
|
+ disabled={isConnecting}
|
|
|
|
|
+ error={phoneNumberError}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<Button
|
|
<Button
|
|
|
onClick={handleConnect}
|
|
onClick={handleConnect}
|
|
|
disabled={isConnecting}
|
|
disabled={isConnecting}
|