Skip to content

Commit

Permalink
binding order note state
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyos committed May 6, 2024
1 parent 7d4fce0 commit bf33cc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/pages/cart/delivery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { Box, Icon, Input, Text } from "zmp-ui";
import { PersonPicker, RequestPersonPickerPhone } from "./person-picker";
import { RequestStorePickerLocation, StorePicker } from "./store-picker";
import { TimePicker } from "./time-picker";
import { useRecoilState } from "recoil";
import { orderNoteState } from "state";

export const Delivery: FC = () => {
const [note, setNote] = useRecoilState(orderNoteState);

return (
<Box className="space-y-3 px-4">
<Text.Header>Hình thức nhận hàng</Text.Header>
Expand Down Expand Up @@ -50,6 +54,8 @@ export const Delivery: FC = () => {
placeholder="Nhập ghi chú..."
className="border-none px-0 w-full focus:outline-none"
maxRows={4}
value={note}
onChange={(e) => setNote(e.currentTarget.value)}
/>
</Box>
),
Expand Down
27 changes: 16 additions & 11 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const productsState = selector<Product[]>({
({
...product,
variants: variants.filter((variant) =>
product.variantId.includes(variant.id),
product.variantId.includes(variant.id)
),
}) as Product,
} as Product)
);
},
});
Expand All @@ -80,7 +80,7 @@ export const productsByCategoryState = selectorFamily<Product[], string>({
({ get }) => {
const allProducts = get(productsState);
return allProducts.filter((product) =>
product.categoryId.includes(categoryId),
product.categoryId.includes(categoryId)
);
},
});
Expand All @@ -105,7 +105,7 @@ export const totalPriceState = selector({
return cart.reduce(
(total, item) =>
total + item.quantity * calcFinalPrice(item.product, item.options),
0,
0
);
},
});
Expand Down Expand Up @@ -144,7 +144,7 @@ export const resultState = selector<Product[]>({
const products = get(productsState);
await wait(500);
return products.filter((product) =>
product.name.trim().toLowerCase().includes(keyword.trim().toLowerCase()),
product.name.trim().toLowerCase().includes(keyword.trim().toLowerCase())
);
},
});
Expand Down Expand Up @@ -211,13 +211,13 @@ export const nearbyStoresState = selector({
location.latitude,
location.longitude,
store.lat,
store.long,
store.long
),
}));

// Sort the stores by distance from the current location
const nearbyStores = storesWithDistance.sort(
(a, b) => a.distance - b.distance,
(a, b) => a.distance - b.distance
);

return nearbyStores;
Expand Down Expand Up @@ -271,11 +271,11 @@ export const locationState = selector<
if (token) {
console.warn(
"Sử dụng token này để truy xuất vị trí chính xác của người dùng",
token,
token
);
console.warn(
"Chi tiết tham khảo: ",
"https://mini.zalo.me/blog/thong-bao-thay-doi-luong-truy-xuat-thong-tin-nguoi-dung-tren-zalo-mini-app",
"https://mini.zalo.me/blog/thong-bao-thay-doi-luong-truy-xuat-thong-tin-nguoi-dung-tren-zalo-mini-app"
);
console.warn("Giả lập vị trí mặc định: VNG Campus");
return {
Expand All @@ -299,15 +299,20 @@ export const phoneState = selector<string | boolean>({
}
console.warn(
"Sử dụng token này để truy xuất số điện thoại của người dùng",
token,
token
);
console.warn(
"Chi tiết tham khảo: ",
"https://mini.zalo.me/blog/thong-bao-thay-doi-luong-truy-xuat-thong-tin-nguoi-dung-tren-zalo-mini-app",
"https://mini.zalo.me/blog/thong-bao-thay-doi-luong-truy-xuat-thong-tin-nguoi-dung-tren-zalo-mini-app"
);
console.warn("Giả lập số điện thoại mặc định: 0337076898");
return "0337076898";
}
return false;
},
});

export const orderNoteState = atom({
key: "orderNote",
default: "",
});

0 comments on commit bf33cc3

Please sign in to comment.