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

VBM-245: Fix/buy button for product author #528

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
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ import { AuctionLeaveModal } from './auction-leave-modal';
type LotPriceBlockProps = Pick<
ProductDto,
'id' | 'currentPrice' | 'minimalBid'
>;
> & { isAuthor: boolean; isSold: boolean };

const LotPriceBlock: FC<LotPriceBlockProps> = ({
id,
currentPrice,
minimalBid,
isAuthor,
isSold,
}) => {
const { colors } = useCustomTheme();
const { t } = useTranslation();
Expand Down Expand Up @@ -160,45 +162,47 @@ const LotPriceBlock: FC<LotPriceBlockProps> = ({
editable={canUserMakeBid}
contentContainerStyle={styles.input}
/>
<View
style={[
globalStyles.flexDirectionRow,
globalStyles.alignItemsCenter,
]}
>
{!!isAbleToLeaveAuction && user && (
<TouchableHighlight
onPress={openModal}
style={[
globalStyles.justifyContentCenter,
globalStyles.alignItemsCenter,
globalStyles.flexDirectionRow,
globalStyles.mr3,
globalStyles.ml3,
styles.iconBorder,
styles.leaveBtn,
]}
>
<CrossIcon color={ColorPalette.WHITE_100} size={25} />
</TouchableHighlight>
)}
<View style={styles.btnWidth}>
<PrimaryButton
iconLeft={<PlusIcon size={10} color={colors.whiteColor} />}
isLoading={isLoading}
onPress={handleSubmit(handleMakeBidPress)}
label={`${t('common:components.BUTTON_BID')}`}
disabled={!canUserMakeBid}
/>
{!isAuthor && (
<View
style={[
globalStyles.flexDirectionRow,
globalStyles.alignItemsCenter,
]}
>
{!!isAbleToLeaveAuction && user && (
<TouchableHighlight
onPress={openModal}
style={[
globalStyles.justifyContentCenter,
globalStyles.alignItemsCenter,
globalStyles.flexDirectionRow,
globalStyles.mr3,
globalStyles.ml3,
styles.iconBorder,
styles.leaveBtn,
]}
>
<CrossIcon color={ColorPalette.WHITE_100} size={25} />
</TouchableHighlight>
)}
<View style={styles.btnWidth}>
<PrimaryButton
iconLeft={<PlusIcon size={10} color={colors.whiteColor} />}
isLoading={isLoading}
onPress={handleSubmit(handleMakeBidPress)}
label={`${t('common:components.BUTTON_BID')}`}
disabled={!canUserMakeBid || isSold}
/>
</View>
<View style={[globalStyles.ml5, styles.iconBorder]}>
<StarIcon
size={25}
color={ColorPalette.YELLOW_200}
style={styles.icon}
/>
</View>
</View>
<View style={[globalStyles.ml5, styles.iconBorder]}>
<StarIcon
size={25}
color={ColorPalette.YELLOW_200}
style={styles.icon}
/>
</View>
</View>
)}
</>
</PriceWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ import { selectCurrentUser } from '~/store/selectors';
import { PriceWrapper } from './price-wrapper';
import { styles } from './styles';

type ProductPriceBlockProps = Pick<ProductDto, 'price'>;
type ProductPriceBlockProps = Pick<ProductDto, 'price'> & {
isAuthor: boolean;
isSold: boolean;
};

const ProductPriceBlock: FC<ProductPriceBlockProps> = ({ price }) => {
const ProductPriceBlock: FC<ProductPriceBlockProps> = ({
price,
isAuthor,
isSold,
}) => {
const { colors } = useCustomTheme();
const { t } = useTranslation();
const user = useAppSelector(selectCurrentUser);
Expand All @@ -27,23 +34,28 @@ const ProductPriceBlock: FC<ProductPriceBlockProps> = ({ price }) => {
>
{`${price} ${t('common:currency.UAH')}`}
</Text>
<View
style={[globalStyles.flexDirectionRow, globalStyles.alignItemsCenter]}
>
<View style={styles.btnWidth}>
<PrimaryButton
label={t('common:components.BUTTON_BUY')}
disabled={!canUserMakeBid}
/>
</View>
<View style={[globalStyles.ml5, styles.iconBorder]}>
<StarIcon
size={25}
color={ColorPalette.YELLOW_200}
style={styles.icon}
/>
{!isAuthor && (
<View
style={[
globalStyles.flexDirectionRow,
globalStyles.alignItemsCenter,
]}
>
<View style={styles.btnWidth}>
<PrimaryButton
label={t('common:components.BUTTON_BUY')}
disabled={!canUserMakeBid || isSold}
/>
</View>
<View style={[globalStyles.ml5, styles.iconBorder]}>
<StarIcon
size={25}
color={ColorPalette.YELLOW_200}
style={styles.icon}
/>
</View>
</View>
</View>
)}
</>
</PriceWrapper>
);
Expand Down
31 changes: 9 additions & 22 deletions packages/mobile/src/screens/product-info/product-info.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import dayjs from 'dayjs';
import React, { FC, useEffect } from 'react';
import { RouteProp } from '@react-navigation/native';
import { RootNavigationParamList } from '~/common/types/types';
import {
ProductType,
UpdateProductPriceEvent,
UPDATE_PRODUCT_PRICE,
} from '@vse-bude/shared';
import { ProductType } from '@vse-bude/shared';
import { products as productsActions } from '~/store/actions';
import {
useAppDispatch,
useAppSelector,
useCustomTheme,
useRoute,
useTranslation,
} from '~/hooks/hooks';
import { DataStatus, RootScreenName } from '~/common/enums/enums';
import {
Expand All @@ -31,7 +27,6 @@ import {
selectCurrentUser,
selectDataStatusProducts,
} from '~/store/selectors';
import { notification, socketApi } from '~/services/services';
import {
Description,
ImageCarousel,
Expand All @@ -43,7 +38,6 @@ import {
const ProductInfo: FC = () => {
const { colors } = useCustomTheme();
const dispatch = useAppDispatch();
const { t } = useTranslation();
const product = useAppSelector(selectCurrentProduct);
const dataStatusProduct = useAppSelector(selectDataStatusProducts);
const isLoading = dataStatusProduct === DataStatus.PENDING;
Expand All @@ -57,19 +51,7 @@ const ProductInfo: FC = () => {
useEffect(() => {
dispatch(productsActions.loadProductInfo(id));
dispatch(productsActions.updateProductViews(id));

const socket = socketApi.getAuctionItemIo(id);
socket.on(UPDATE_PRODUCT_PRICE, (data: UpdateProductPriceEvent) => {
dispatch(productsActions.updateCurrentItemPrice(data));
if (data.bidderId !== user?.id || !user) {
notification.info(t('screens:product_info.NEW_BID'));
}
});

if (user) {
dispatch(productsActions.auctionPermissions(id));
}
}, [id, user, dispatch]);
}, [id, dispatch]);

if (!product || isLoading) {
return <Spinner isOverflow={true} />;
Expand All @@ -86,6 +68,9 @@ const ProductInfo: FC = () => {
author,
} = product;
const isAuction = type == ProductType.AUCTION;
const isAuthor = user?.id === product.author.id;
const today = dayjs();
const isSold = today.diff(product.endDate) > 0 ? true : false;

return (
<ScreenWrapper>
Expand Down Expand Up @@ -132,9 +117,11 @@ const ProductInfo: FC = () => {
id={id}
currentPrice={currentPrice}
minimalBid={minimalBid}
isAuthor={isAuthor}
isSold={isSold}
/>
) : (
<ProductPriceBlock price={price} />
<ProductPriceBlock price={price} isAuthor={isAuthor} isSold={isSold} />
)}
</ScreenWrapper>
);
Expand Down