fix: Add region search filter + pre-select on edit + create plan doc

##  Issue #1: TAX_NOTIFICATIONS_PLAN.md Created
- Complete implementation plan for Tax & Notifications
- 80/20 rule: Core features vs Advanced (WooCommerce)
- API endpoints defined
- Implementation phases prioritized

##  Issue #2: Region Search Filter
- Added search input above region list
- Real-time filtering as you type
- Shows "No regions found" when no matches
- Clears search on dialog close/cancel
- Makes finding countries/states MUCH faster!

##  Issue #3: Pre-select Regions on Edit
- Backend now returns raw `locations` array
- Frontend uses `defaultChecked` with location matching
- Existing regions auto-selected when editing zone
- Works correctly for countries, states, and continents

## UX Improvements:
- Search placeholder: "Search regions..."
- Filter is case-insensitive
- Empty state when no results
- Clean state management (clear on close)

Now zone editing is smooth and fast!
This commit is contained in:
dwindown
2025-11-10 10:16:51 +07:00
parent 3d9af05a25
commit 93e5a9a3bc
3 changed files with 159 additions and 19 deletions

View File

@@ -42,6 +42,7 @@ export default function ShippingPage() {
const [showAddZone, setShowAddZone] = useState(false);
const [editingZone, setEditingZone] = useState<any | null>(null);
const [deletingZone, setDeletingZone] = useState<any | null>(null);
const [regionSearch, setRegionSearch] = useState('');
const isDesktop = useMediaQuery("(min-width: 768px)");
// Fetch shipping zones from WooCommerce
@@ -877,6 +878,7 @@ export default function ShippingPage() {
if (!open) {
setShowAddZone(false);
setEditingZone(null);
setRegionSearch('');
}
}}>
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
@@ -927,6 +929,16 @@ export default function ShippingPage() {
<p className="text-xs text-muted-foreground mb-3">
{__('Select countries, states, or continents for this zone')}
</p>
{/* Search Filter */}
<input
type="text"
placeholder={__('Search regions...')}
value={regionSearch}
onChange={(e) => setRegionSearch(e.target.value)}
className="w-full px-3 py-2 border rounded-md mb-2"
/>
<div className="border rounded-md max-h-[300px] overflow-y-auto">
{availableLocations.length === 0 ? (
<div className="p-4 text-center text-sm text-muted-foreground">
@@ -934,20 +946,32 @@ export default function ShippingPage() {
</div>
) : (
<div className="divide-y">
{availableLocations.map((location: any) => (
<label
key={location.code}
className="flex items-center gap-3 p-3 hover:bg-accent cursor-pointer"
>
<input
type="checkbox"
name="regions"
value={location.code}
className="rounded"
/>
<span className="text-sm">{location.label}</span>
</label>
))}
{availableLocations
.filter((location: any) =>
location.label.toLowerCase().includes(regionSearch.toLowerCase())
)
.map((location: any) => (
<label
key={location.code}
className="flex items-center gap-3 p-3 hover:bg-accent cursor-pointer"
>
<input
type="checkbox"
name="regions"
value={location.code}
defaultChecked={editingZone?.locations?.some((l: any) => l.code === location.code)}
className="rounded"
/>
<span className="text-sm">{location.label}</span>
</label>
))}
{availableLocations.filter((location: any) =>
location.label.toLowerCase().includes(regionSearch.toLowerCase())
).length === 0 && (
<div className="p-4 text-center text-sm text-muted-foreground">
{__('No regions found')}
</div>
)}
</div>
)}
</div>
@@ -960,6 +984,7 @@ export default function ShippingPage() {
onClick={() => {
setShowAddZone(false);
setEditingZone(null);
setRegionSearch('');
}}
>
{__('Cancel')}