Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SBS-16][SBS-22] feat: integrate get products api #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 69 additions & 68 deletions app/components/ProductItem.tsx
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
import { Ionicons } from "@expo/vector-icons";
import { colors, spacing } from "app/theme";
import React from "react";
import { View, ViewStyle, ImageStyle, TextStyle } from "react-native";
import { TouchableOpacity } from "react-native-gesture-handler";
import React, { useState } from "react";
import { View, ViewStyle, ImageStyle, TextStyle, TouchableOpacity } from "react-native";
import { AutoImage } from "./AutoImage";
import { Text } from "./Text";
import StarRating from "react-native-star-rating-widget";
import { useNavigation } from "@react-navigation/native";

export interface Product {
id: number;
name: string;
price: number;
minPrice: number;
maxPrice: number;
imageUrl: string;
description: string;
sold: number;
rating: number;
isFavorite: boolean;
discount: number;
}

export interface ProductItemProps {
product: Product;
}
const ProductItem = (props: ProductItemProps) => {
const { name, price, imageUrl, rating, isFavorite, discount } = props.product;
const discountedPriceTx = price - (price * discount) / 100;
return (
<View style={$container}>
<AutoImage maxWidth={190} maxHeight={190} source={{ uri: imageUrl }} style={$image} />

<View style={$favoriteContainer}>
<TouchableOpacity
onPress={() => {
console.log("Favorite button pressed");
}}
style={$favoriteButton}
>
<Ionicons
name={isFavorite ? "heart" : "heart-outline"}
size={24}
color={isFavorite ? "red" : "black"}
/>
</TouchableOpacity>
</View>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
phamhongphuc1403 marked this conversation as resolved.
Show resolved Hide resolved
const { id, name, minPrice, maxPrice, imageUrl, sold, rating } = props.product;
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat("vi-VN", { style: "currency", currency: "VND" }).format(amount);
};

const navigation = useNavigation<any>();

const handleProductDetail = () => {
navigation.navigate("ProductDetailScreen", { id: id });
};

const [setRating] = useState(0);

<View style={$infor}>
return (
<TouchableOpacity onPress={handleProductDetail} style={$container}>
<View>
<View>
<Text style={$productName} text={name} />
</View>
<View style={$priceContainer}>
<Text style={$discountedPrice} text={`$${discountedPriceTx}`} size="sm" />
<Text style={$originalPrice} text={`$${price}`} size="xs" />
<Text style={$discountAmount} text={`${discount}% OFF`} size="xs" />
<AutoImage
maxWidth={190}
maxHeight={190}
source={{ uri: imageUrl }}
style={$image}
resizeMode="cover"
/>
</View>
<View style={$ratingContainer}>
<Ionicons name="star-outline" size={20} color="gold" />
<Text text={`${rating} (100)`} size="md" />

<View style={$infor}>
<View>
<Text style={$productName} text={name} numberOfLines={2} />
</View>
<View style={$priceContainer}>
<Text style={$discountedPrice} text={`${formatCurrency(minPrice)}`} size="sm" />
</View>
<View style={$ratingSoldContainer}>
<View style={$ratingContainer}>
<StarRating
rating={rating}
onChange={setRating}
starSize={20}
starStyle={{ marginHorizontal: spacing.xxxs }}
style={{ marginRight: spacing.xs }}
/>
<Text text={`${rating}/5`} size="md" />
</View>
<View style={$soldContainer}>
<Text tx="productItem.sold"></Text>
<Text text={`${sold}`}></Text>
</View>
</View>
</View>
</View>
</View>
</TouchableOpacity>
);
};

const $container: ViewStyle = {
flex: 1,
padding: spacing.sm,
borderWidth: 1,
borderRadius: 5,
borderColor: colors.gray,
};

const $image: ViewStyle & ImageStyle = {
borderRadius: 15,
padding: spacing.xxs,
marginBottom: spacing.xs,
width: "100%",
};

const $infor: ViewStyle = {
alignItems: "flex-start",
};

const $favoriteContainer: ViewStyle = {
alignItems: "center",
backgroundColor: colors.palette.white,
borderBlockColor: "black",
borderRadius: spacing.md,
height: 40,
justifyContent: "center",
position: "absolute",
right: 20,
top: 20,
width: 40,
zIndex: 1,
};

const $favoriteButton: ViewStyle = {
alignItems: "center",
height: "100%",
justifyContent: "center",
width: "100%",
};

const $productName: TextStyle = {
fontWeight: "normal",
marginBottom: spacing.xxs,
Expand All @@ -111,19 +111,20 @@ const $discountedPrice: TextStyle = {
marginRight: spacing.xxs,
};

const $originalPrice: TextStyle = {
color: colors.palette.gray,
marginRight: spacing.xxs,
textDecorationLine: "line-through",
const $ratingContainer: TextStyle = {
alignItems: "flex-start",
flexDirection: "row",
};

const $discountAmount: TextStyle = {
color: colors.palette.red,
const $ratingSoldContainer: ViewStyle = {
alignItems: "flex-start",
flexDirection: "column",
};

const $ratingContainer: TextStyle = {
alignItems: "center",
const $soldContainer: TextStyle = {
alignItems: "flex-start",
flexDirection: "row",
gap: spacing.xs,
};

export default ProductItem;
2 changes: 1 addition & 1 deletion app/config/config.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* https://reactnative.dev/docs/security#storing-sensitive-info
*/
export default {
API_URL: "http://localhost:3000/api",
API_URL: "https://2bw10hcq-3000.asse.devtunnels.ms/api",
};
3 changes: 3 additions & 0 deletions app/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ const en = {
notFound: "No Results Found",
results: "results",
},
productItem: {
sold: "Sold",
},
};

export default en;
Expand Down
Loading