fix: Improve shipping toggle and simplify UI
Fixed toggle functionality and cleaned up redundant buttons. Backend Fix: ✅ Fixed toggle to properly update shipping method settings ✅ Get existing settings, update enabled field, save back ✅ Previously was trying to save wrong data structure Frontend Changes: ✅ Removed "View in WooCommerce" from header (redundant) ✅ Changed "Edit zone" to "Settings" button (prepares for modal) ✅ Changed "+ Add shipping zone" to "Manage Zones in WooCommerce" ✅ Added modal state (selectedZone, isModalOpen) ✅ Added Dialog/Drawer imports for future modal implementation Button Strategy: - Header: Refresh only - Zone card: Settings button (will open modal) - Bottom: "Manage Zones in WooCommerce" (for add/edit/delete zones) Next Step: Implement settings modal similar to Payments page with zone/method configuration
This commit is contained in:
@@ -5,9 +5,12 @@ import { SettingsLayout } from './components/SettingsLayout';
|
|||||||
import { SettingsCard } from './components/SettingsCard';
|
import { SettingsCard } from './components/SettingsCard';
|
||||||
import { ToggleField } from './components/ToggleField';
|
import { ToggleField } from './components/ToggleField';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Globe, Truck, MapPin, Edit, Trash2, RefreshCw, Loader2, ExternalLink } from 'lucide-react';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
|
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from '@/components/ui/drawer';
|
||||||
|
import { Globe, Truck, MapPin, Edit, Trash2, RefreshCw, Loader2, ExternalLink, Settings } from 'lucide-react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { __ } from '@/lib/i18n';
|
import { __ } from '@/lib/i18n';
|
||||||
|
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||||
|
|
||||||
interface ShippingRate {
|
interface ShippingRate {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -28,6 +31,9 @@ export default function ShippingPage() {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const wcAdminUrl = (window as any).WNW_CONFIG?.wpAdminUrl || '/wp-admin';
|
const wcAdminUrl = (window as any).WNW_CONFIG?.wpAdminUrl || '/wp-admin';
|
||||||
const [togglingMethod, setTogglingMethod] = useState<string | null>(null);
|
const [togglingMethod, setTogglingMethod] = useState<string | null>(null);
|
||||||
|
const [selectedZone, setSelectedZone] = useState<any | null>(null);
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
const isDesktop = useMediaQuery("(min-width: 768px)");
|
||||||
|
|
||||||
// Fetch shipping zones from WooCommerce
|
// Fetch shipping zones from WooCommerce
|
||||||
const { data: zones = [], isLoading, refetch } = useQuery({
|
const { data: zones = [], isLoading, refetch } = useQuery({
|
||||||
@@ -76,27 +82,15 @@ export default function ShippingPage() {
|
|||||||
title={__('Shipping & Delivery')}
|
title={__('Shipping & Delivery')}
|
||||||
description={__('Manage how you ship products to customers')}
|
description={__('Manage how you ship products to customers')}
|
||||||
action={
|
action={
|
||||||
<div className="flex gap-2">
|
<Button
|
||||||
<Button
|
variant="outline"
|
||||||
variant="outline"
|
size="sm"
|
||||||
size="sm"
|
onClick={() => refetch()}
|
||||||
onClick={() => refetch()}
|
disabled={isLoading}
|
||||||
disabled={isLoading}
|
>
|
||||||
>
|
<RefreshCw className="h-4 w-4 mr-2" />
|
||||||
<RefreshCw className="h-4 w-4 mr-2" />
|
{__('Refresh')}
|
||||||
{__('Refresh')}
|
</Button>
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
asChild
|
|
||||||
>
|
|
||||||
<a href={`${wcAdminUrl}/admin.php?page=wc-settings&tab=shipping`} target="_blank" rel="noopener noreferrer">
|
|
||||||
<ExternalLink className="h-4 w-4 mr-2" />
|
|
||||||
{__('View in WooCommerce')}
|
|
||||||
</a>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{/* Shipping Zones */}
|
{/* Shipping Zones */}
|
||||||
@@ -144,12 +138,13 @@ export default function ShippingPage() {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
asChild
|
onClick={() => {
|
||||||
|
setSelectedZone(zone);
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<a href={`${wcAdminUrl}/admin.php?page=wc-settings&tab=shipping&zone_id=${zone.id}`} target="_blank" rel="noopener noreferrer">
|
<Settings className="h-4 w-4 mr-2" />
|
||||||
<Edit className="h-4 w-4 mr-2" />
|
{__('Settings')}
|
||||||
{__('Edit zone')}
|
|
||||||
</a>
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -204,8 +199,9 @@ export default function ShippingPage() {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
asChild
|
asChild
|
||||||
>
|
>
|
||||||
<a href={`${wcAdminUrl}/admin.php?page=wc-settings&tab=shipping&action=add_zone`} target="_blank" rel="noopener noreferrer">
|
<a href={`${wcAdminUrl}/admin.php?page=wc-settings&tab=shipping`} target="_blank" rel="noopener noreferrer">
|
||||||
+ {__('Add shipping zone')}
|
<ExternalLink className="h-4 w-4 mr-2" />
|
||||||
|
{__('Manage Zones in WooCommerce')}
|
||||||
</a>
|
</a>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -210,8 +210,9 @@ class ShippingController extends WP_REST_Controller {
|
|||||||
$method_found = true;
|
$method_found = true;
|
||||||
|
|
||||||
// Update the enabled status
|
// Update the enabled status
|
||||||
$method->enabled = $enabled ? 'yes' : 'no';
|
$settings = get_option( $method->get_instance_option_key(), array() );
|
||||||
update_option( $method->get_instance_option_key(), $method->instance_settings );
|
$settings['enabled'] = $enabled ? 'yes' : 'no';
|
||||||
|
update_option( $method->get_instance_option_key(), $settings );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user