diff --git a/docs/address-form-keyboard-fix.md b/docs/address-form-keyboard-fix.md deleted file mode 100644 index 446d3eb..0000000 --- a/docs/address-form-keyboard-fix.md +++ /dev/null @@ -1,115 +0,0 @@ -# Address form: keyboard not appearing (iOS) — fix - -Status: fixed (user-ui). Applies to iOS simulator and physical devices. -File changed: `apps/user-ui/src/components/AddressForm.tsx` - -## Symptom - -On iOS, tapping an input in the address form sometimes focused the field (cursor + iOS -edit menu visible) but the software keyboard did not appear on screen, or appeared -**off-screen**. Other forms in the app (login, complaints, order notes) showed the -keyboard normally. - -Captured evidence on the iOS 18.6 simulator: the input was focused while the keyboard's -`SystemInputAssistantView` bounds were `[0,896][414,1211]` — i.e. starting at the bottom -edge of the 896pt screen and extending below it. A second tap brought the keyboard up. - -## Root cause - -`AddressForm` was the only form still using `react-native-keyboard-aware-scroll-view` -(installed `0.9.5`, last published ~2021) via `KeyboardAwareScrollView`. - -That library measures the focused input with the legacy bridge APIs: - -``` -node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js - -> findNodeHandle / UIManager / measureInWindow / TextInputState -``` - -The app runs `react-native@0.79.6` with `newArchEnabled: true` (Fabric/TurboModules). -Those legacy measurement APIs are unreliable under the New Architecture (stale/zero -measurements, bad ordering), so the library's scroll-into-view / keyboard handling can -leave the keyboard mis-positioned or suppressed. - -Every other working form in the app uses React Native's built-in `KeyboardAvoidingView` -instead, which is why they were unaffected. - -## Is this simulator-only? - -No. The affected code is the library's JS/native HOC, which ships and runs identically on -physical iPhones. The simulator simply reproduced it. Whether you *see* it depends on -geometry and timing (keyboard height, screen size, content height, safe area, animation -timing), so on a device the visible symptom could be "keyboard shows but the field is -scrolled wrong/hidden" rather than exactly "no keyboard". - -## The fix - -Replace the legacy `KeyboardAwareScrollView` with the app's standard `KeyboardAvoidingView` -+ `ScrollView` pattern. - -Before: - -```tsx -import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'; - - - ... - -``` - -After: - -```tsx -import { View, Modal, ScrollView, KeyboardAvoidingView, Platform } from 'react-native'; - - - - ... - - -``` - -Notes: -- `behavior="padding"` on iOS (`undefined` on Android, where `softwareKeyboardLayoutMode: "resize"` is set in `app.json`). -- The scroll container now fills its parent (`flex-1`); padding moved to `contentContainerStyle`. - This also fixed a pre-existing layout bug where `pb-32` (viewport padding) plus a hardcoded - `maxHeight: 70%` left a blank band at the bottom and clipped content on the full-screen - add-address step. - -Related wrapper fix (the sheet has no built-in height): `apps/user-ui/app/(drawer)/(tabs)/me/addresses/index.tsx` -wraps the form in a sized container because `RawBottomDialog` renders children bare: - -```tsx - setModalVisible(false)}> - - - - -``` - -## Verification - -- iOS simulator (iOS 18.6): tapping an input shows the keyboard on-screen - (`SystemInputAssistantView` top at y≈550 instead of y=896); the focused field scrolls into - view and the submit button remains reachable. -- End-to-end: added an address via "Attach Current Location"; the region switched and Home loaded. -- `tsc --noEmit` clean for user-ui. -- No dependency changes; no migrations. - -## Remaining risk - -`apps/user-ui/app/(auth)/login.tsx` still uses `KeyboardAwareScrollView` from the same -legacy library. It is the same latent risk on devices under the New Architecture; migrate -to `KeyboardAvoidingView` for consistency when convenient. diff --git a/docs/handy-test-plan.txt b/docs/handy-test-plan.txt new file mode 100644 index 0000000..6779c1b --- /dev/null +++ b/docs/handy-test-plan.txt @@ -0,0 +1,20 @@ +in superadmin-ui +-> Create 3 regions with the bounds in map-assets folder +-> create an admin for each region. +-> Create 2 global stores and 2 globl products +-> elevate a local store from Mahabubnagar to global. Elevate a product to that store too + +login with each admin account in admin-ui and do these +-> create a store with an image uploaded +-> create a product in that store +-> create slots for those products +-> add separate minimum order thresholds for each bound in region. + +then open user app with location enabled in Mahabubnagar region's bound 1. If already logged in logout and restart app +-> Expect the region's products to show up +-> place an order in that region. +-> then manually add an address in another region with map. use the + and - symbols on top right dont squeeze or pinch +-> Switch to that region and expect it's products to be shown. +-> In the same region, try to add another address but in second bound. +-> test the change infree delivery thresholds and also the delivery charge. + diff --git a/docs/multi-region-i2-review.md b/docs/multi-region-i2-review.md deleted file mode 100644 index d4e034d..0000000 --- a/docs/multi-region-i2-review.md +++ /dev/null @@ -1,111 +0,0 @@ -# MULTI_REGION_I2 code review - -## Scope and result - -- Comparison: `main...HEAD` -- Reviewed HEAD: `d892cfbc2b1c6c4b2bccaf32b368013393a8e139` -- Base main: `a09cb936c09d728d76063023b4ec89aed426e8f8` -- Focus: discovery contracts, global-product editing, regional market data, and coupon pricing/checkout. -- Result: **7 confirmed outstanding findings: 3 P1 and 4 P2.** -- This is a static review, not an exhaustive validation of every changed file. No test suites, builds, or migrations were run during this re-review. No application code was changed. -- The unrelated uncommitted Expo cache file was excluded from the branch review. - -P1 means a high-priority functional or financial correctness issue. P2 means a normal-priority correctness issue under the described scenario. - -## Resolved finding from the previous review - -### Shared pricing exports are now committed - -`packages/shared/index.ts:22–23` now exports `./cart-pricing`. The previous finding that a clean checkout lacks the shared pricing exports is resolved and is not counted below. - -## Outstanding findings - -### R1 — [P1] Web discovery sends regionId where the backend requires boundId - -**Location:** `apps/web-ui/src/hooks/prominent-api-hooks.ts:25–27` - -**Scenario:** Open the web storefront and select a browsing region. - -The hook calls `common.essentialConsts` with `{ regionId }`. The backend input schema in `apps/backend/src/trpc/apis/common-apis/common-trpc-index.ts:267–278` requires a positive `boundId`. The `as any` bypasses compile-time checking but not Zod validation, so the discovery request fails. With no discovery response, the cache URL builders cannot obtain the asset domain and version values, blocking catalog, availability, and slot loading on a fresh session. - -**Suggested fix:** Resolve the applicable delivery/browsing bound, send `{ boundId }`, and enable the query only when that bound is available. Remove the cast hiding the contract mismatch. Keep the bound in the query input so switching bounds refreshes delivery constants. - -**Verification:** A fresh web session can load the selected region's catalog, and switching between bounds refreshes the bound-specific delivery settings. - -### R2 — [P1] Global-product updates strip existing SKU IDs and insert duplicates - -**Location:** `apps/backend/src/trpc/apis/superadmin-apis/apis/global-products.ts:95–107` - -**Scenario:** A superadmin saves an existing global product after changing an image, feature, or suspension flag. - -The update schema uses `skuInput`, which does not declare an `id` field. Zod strips unknown properties, including the SKU IDs sent by the UI. Consequently `(sku as any).id` is undefined in the handler. The database helper's existing-SKU branch at `packages/db_helper_sqlite/src/admin-apis/product.ts:663–674` is skipped, and the new-SKU branch at lines 731–751 inserts duplicate variants and market-stat rows. The original variants remain unchanged; an original SKU can remain orderable even when the intended edit suspends its replacement. - -**Suggested fix:** Define an update SKU schema that preserves an optional positive integer `id`, and map its typed field directly. Validate that supplied existing IDs belong to the edited product; only variants intentionally lacking an ID should be inserted. - -**Verification:** Editing an existing variant preserves its ID and the product's SKU count. Adding one new variant increases the count by exactly one. - -### R3 — [P1] Overlapping targeted coupons can create negative sub-order totals - -**Location:** `packages/shared/cart-pricing.ts:158–181` - -**Scenario:** A scheduled cart has ₹100 of SKU A in one slot and ₹900 of unrelated goods in another slot. Two nonexclusive ₹100 coupons both target SKU A. - -Each coupon is calculated against the original ₹100 eligible subtotal and allocates ₹100 to the first sub-order. The combined ₹200 discount is below the ₹1,000 whole-cart subtotal, so the global cap does not run. The first sub-order receives ₹200 of discount on ₹100 of goods and stores a **−₹100 total**; the unrelated sub-order still costs ₹900. This effectively uses the targeted coupons to offset goods outside their targets and persists an invalid negative payable sub-order. - -**Suggested fix:** Track remaining discountable value per line when applying coupons, allocating only discounts that those eligible lines can absorb. Derive coupon shares, sub-order discounts, and the cart total from the same capped allocation. A whole-cart cap or a final zero clamp alone does not enforce product targeting. - -**Verification:** In the example, SKU A can receive at most ₹100 combined discount; the unrelated goods remain ₹900 and every sub-order total is nonnegative. Also verify partially overlapping target sets. - -### R4 — [P2] Mobile cart and checkout previews omit the combined discount cap - -**Locations:** - -- `apps/user-ui/components/checkout-page.tsx:230–244` -- `apps/user-ui/components/cart-page.tsx:434–448` - -**Scenario:** A ₹100 cart has two eligible nonexclusive ₹80 flat coupons. - -The UI sums the individual discounts to ₹160 and displays a −₹60 goods total before delivery. The backend's `computeCartPricing` caps the combined discount at ₹100. The customer therefore sees a different payable amount from the stored order, and delivery-threshold calculations can also diverge because they use the uncapped preview total. - -**Suggested fix:** Use the shared cart-pricing result in both screens instead of independently summing `computeCouponDiscount` results. Ensure the pricing lines are the same available items that will actually be submitted. - -**Verification:** Cart, checkout, and stored order agree when multiple coupons exceed the goods subtotal, including cases where the delivery threshold is affected. - -### R5 — [P2] Reopening a global product loses its regional suspension state - -**Location:** `packages/db_helper_sqlite/src/admin-apis/product.ts:198–200` - -**Scenario:** A regional admin enables “Suspend in my region” for a globally unsuspended SKU, saves it, reopens it, and saves an unrelated price edit. - -`mapSku` returns `sku.isSuspended` but omits `marketStats.isSuspendedInRegion`. The regional form initializes its checkbox from `sku.isSuspended` (`apps/admin-ui/src/components/GlobalProductForm.tsx:37–48`), so the saved regional suspension appears false after reopening. Submitting the price edit sends false, and `updateProductMarketDataForRegion` at `packages/db_helper_sqlite/src/admin-apis/product.ts:535–541` clears the regional suspension, making the SKU available again. - -**Suggested fix:** Expose global and regional suspension flags separately in the admin response. Initialize and submit the regional checkbox using `isSuspendedInRegion`, and represent the global kill-switch independently. Apply the same distinction in both regional admin clients. - -**Verification:** A regional suspension survives reopening and unrelated edits. A global suspension does not incorrectly initialize or write the regional flag. - -### R6 — [P2] Prices Overview rejects global SKUs included in its listing - -**Location:** `packages/db_helper_sqlite/src/admin-apis/product.ts:1255–1258` - -**Scenario:** A regional admin edits a global SKU's price or flash availability through Prices Overview, either alone or in a batch with regional SKUs. - -The listing includes global products, but bulk-price validation only accepts products whose `regionId` equals the staff region. Global products have a null region, so they are reported as invalid and the entire batch is rejected. This also prevents valid regional changes in the same batch from being saved. The subsequent market-stat writes are already scoped to the authenticated region. - -**Suggested fix:** Accept SKUs whose parent product is global or belongs to the authenticated region, while continuing to reject another region's regional SKUs. Keep the existing region-scoped writes. - -**Verification:** A mixed global/regional batch saves only the authenticated region's market data; another region's regional SKU remains rejected. - -### R7 — [P2] Targeted-coupon eligibility still compares minOrder with the whole cart - -**Locations:** - -- `apps/user-ui/components/checkout-page.tsx:182–185` -- `apps/user-ui/components/cart-page.tsx:284–286` - -**Scenario:** A coupon requires ₹200 of its targeted SKU, but the cart contains only ₹50 of that SKU plus ₹300 of unrelated goods. - -Both screens mark the coupon eligible because they compare `minOrder` with the whole-cart subtotal. The backend correctly compares it with the ₹50 eligible subtotal in `packages/db_helper_sqlite/src/user-apis/order.ts:187–202`, so placing the order fails after the UI has offered and displayed the coupon. Coupons with no matching cart lines are also not disabled by this eligibility calculation. - -**Suggested fix:** Use `computeEligibleSubtotal` over the actual effective-price, available checkout lines for both the minimum requirement and target-match check. Align the cart and checkout eligibility rules with server validation. - -**Verification:** The example coupon is disabled with the appropriate minimum explanation; a targeted coupon with no matching items is unavailable; flash-priced eligible lines use their flash price. diff --git a/docs/test-cases/README.md b/docs/test-cases/README.md index 0df5824..f188e98 100644 --- a/docs/test-cases/README.md +++ b/docs/test-cases/README.md @@ -6,7 +6,7 @@ This folder contains feature-by-feature acceptance and regression checklists for **All cases are proposed and NOT RUN.** A listed expected result is a requirement to verify, not a claim that the implementation currently satisfies it. Known review defects are intentionally covered. Documentation creation does not authorize running tests, sending notifications, charging payments, deleting data, or applying migrations. -Inventory: **45 feature checklists and 812 uniquely identified cases**, plus this index. Features are grouped by business responsibility; closely related operations share a checklist (for example stock, offer flags and suspension). Reuse the shared boundary/security matrix rather than assuming a finite list can cover every possible input. +Inventory: **45 feature checklists and 815 uniquely identified cases**, plus this index. Features are grouped by business responsibility; closely related operations share a checklist (for example stock, offer flags and suspension). Reuse the shared boundary/security matrix rather than assuming a finite list can cover every possible input. Sources: current routers/screens/helpers, existing API tests, [sanity plan](../e2e-sanity-test-plan.md), and [branch review](../multi-region-i2-review.md). Older sanity-plan statements that coupons ignore regions/SKUs are superseded here by the newer coupon requirements. Vendor snippets and reviews remain conditional/legacy coverage; online gateway cases are readiness coverage until implementation is enabled. diff --git a/docs/test-cases/location-region-switching.md b/docs/test-cases/location-region-switching.md index 5796be3..3301c5e 100644 --- a/docs/test-cases/location-region-switching.md +++ b/docs/test-cases/location-region-switching.md @@ -1,6 +1,6 @@ # Location resolution and region switching -Scope: native location store/useRegion, web region gate/store, manual selector, GPS attachment. The browsing region is **in-memory only and never persisted**: every launch re-derives it from the device location and/or the default address. +Scope: native location store/useRegion, web region gate/store, manual selector, GPS attachment. Platform difference to respect: **native** (`user-ui`) keeps the browsing region **in memory only — never persisted**, re-derived each launch from the device location and/or the default address; **web** (`web-ui`) still **persists** it (`freshyo-region` in localStorage) and its gate resolves no location at all (it validates the saved id against `listRegions`, else shows the region selector). | ID | Priority | Action / input | Expected result | |---|---|---|---| @@ -26,5 +26,10 @@ Scope: native location store/useRegion, web region gate/store, manual selector, | LOC-20 | P1 | Set a region → force-quit → relaunch with location unavailable. | Nothing is persisted: the region is re-derived (default address / location); when neither resolves a chooser appears — a previously set region does not silently survive. | | LOC-21 | P0 | Cold start adopts the first region while a local cart has items. | Adoption uses the non-clearing path (local cart preserved). Only an explicit switch away from an already-set region confirms and clears regional state. | | LOC-22 | P1 | Launch with location access denied, then with device location services off, then with permission granted but no fix. | Distinct messages ("access not granted" vs "services off" vs "couldn't get a fix") plus an "Open location settings" action, then an address-chooser fallback. | +| LOC-23 | P1 | Signed out, no region resolves (location off/denied/out-of-area). | The chooser shows "Login to get existing addresses." with a Login action. Tapping it shows the login screen **in place** (the gate renders outside the navigator, so no route push), and after a successful login the chooser returns with the account's saved addresses selectable; backing out leaves region/cart untouched. | +| LOC-24 | P2 | A region-gate screen (no region yet) offers any "go to another route" action. | The action works without a mounted navigator (inline screen/state change), because `LocationTestWrapper` / `FirstUserWrapper` / `HealthTestWrapper` replace the root ``; a `router.push`/`router.back` there must not silently no-op. | +| LOC-25 | P1 | The device fix succeeds but the point is outside every bound, with and without a saved default address. | With a default address: that region is used. Without one: an explicit "outside our delivery area" state is shown on the chooser (not a bare chooser with no explanation), and a usable manual path remains. | + +Related: the cart's first-address gate for a signed-in user with zero addresses (even an empty cart) is [CART-23](cart.md); the signed-out address draft that syncs after login is [ADDR-25](addresses.md). Native manual switching is the address switcher sheet, not a region list (the region list selector is web-only). Open policy: exact cold-start/manual-choice precedence after a populated local cart. Do not label ambiguity PASS.