Skip to content

Commit 060caba

Browse files
committed
add chat offer, fix android ui issue
1 parent 5ee2107 commit 060caba

File tree

13 files changed

+80
-15
lines changed

13 files changed

+80
-15
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
API_URL=https://forautobackend.herokuapp.com
2-
API_URL_A=http://localhost:3030
1+
API_URL_A=https://forautobackend.herokuapp.com
2+
API_URL=http://localhost:3030

components/Cards/VehicleCard.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ const VehicleCard = (props) => {
125125
visible={overlayActive}
126126
onClose={() => setOverlayActive(false)}
127127
>
128-
<VehicleCardScreen price={finalPrice} title={vehicleTitle} />
128+
<VehicleCardScreen
129+
listingId={listingId}
130+
price={finalPrice}
131+
title={vehicleTitle}
132+
/>
129133
</VehicleCardOverlay>
130134
<div className={styles.image}>
131135
<BaseButton

components/Cards/VehicleCardScreen/VehicleCardScreen.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const screens = {
1212
type Props = {
1313
price?: number
1414
title: string
15+
listingId: string
1516
}
1617

1718
const VehicleCardScreen: React.FunctionComponent<Props> = ({
1819
price,
1920
title,
21+
listingId,
2022
}) => {
2123
const [screen, setScreen] = useState(screens.BASE)
2224

@@ -35,6 +37,7 @@ const VehicleCardScreen: React.FunctionComponent<Props> = ({
3537
visible={screen === screens.OFFER}
3638
price={price}
3739
title={title}
40+
listingId={listingId}
3841
/>
3942
<BaseScreen
4043
onOfferScreenOpen={() => setScreen(screens.OFFER)}

components/Cards/VehicleCardScreen/screens/OfferScreen.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ type Props = {
1010
visible: boolean
1111
price?: number
1212
title: string
13+
listingId: string
1314
}
1415

1516
const OfferScreen: React.FunctionComponent<Props> = ({
1617
onCancel,
1718
visible,
1819
price,
1920
title,
21+
listingId,
2022
}) => {
2123
const { t } = useTranslation()
2224
if (!visible) return null
2325
return (
2426
<div className={styles.container}>
2527
<h5>{title}</h5>
2628
{price && <p>{price}</p>}
27-
<OfferForm />
29+
{/* @ts-ignore */}
30+
<OfferForm listingId={listingId} />
2831
<Button
2932
color={Button.colors.RED}
3033
onClick={onCancel}

components/Forms/OfferForm.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import React from 'react'
22
import { reduxForm } from 'redux-form'
33
import { useTranslation } from 'react-i18next'
4+
import get from 'lodash/get'
5+
import toNumber from 'lodash/toNumber'
6+
import { useDispatch } from 'react-redux'
47
import { Button, Input } from '~components'
8+
import ChatCreators from '~store/chats/creators'
59
import styles from './OfferForm.module.scss'
610

7-
const OfferForm = ({ handleSubmit, disabled }) => {
11+
const OfferForm = ({ handleSubmit, listingId, disabled }) => {
812
const { t } = useTranslation()
13+
const dispatch = useDispatch()
914
const onSubmit = (val) => {
10-
console.log('values', val)
15+
const offer = get(val, 'offer', 0)
16+
if (listingId && offer && toNumber(offer) > 0) {
17+
dispatch(
18+
ChatCreators.createChat({
19+
listingId,
20+
currency: 'EUR',
21+
offer: toNumber(offer),
22+
redirect: false,
23+
})
24+
)
25+
}
1126
}
1227
return (
1328
<form
@@ -28,7 +43,7 @@ const OfferForm = ({ handleSubmit, disabled }) => {
2843
/>
2944
<Button
3045
fluid
31-
label="Offer"
46+
label={t('button.offer')}
3247
disabled={disabled}
3348
onClick={handleSubmit(onSubmit)}
3449
/>

components/VehicleOfTheDay/VehicleOfTheDay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const VehicleContent: React.FunctionComponent<VehicleOfTheDayProps> = ({
102102
phone={listing.contactPhone}
103103
userId={listing.userId}
104104
/>
105-
<OfferForm />
105+
<OfferForm listingId={listing._id} />
106106
<Price
107107
price={listing.price}
108108
discountedPrice={

components/VehicleOfTheDay/components/VotdActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Props = {
1111
phone?: string | null
1212
email?: string | null
1313
userId: string
14-
listingId: string
14+
listingId?: string
1515
}
1616

1717
const VotdActions: React.FunctionComponent<Props> = ({

pages/listing/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const ListingPage: React.FunctionComponent<Props> = ({ prefetchedListing }) => {
113113
/>
114114
)}
115115
{/* @ts-ignore */}
116-
{!isSold && <OfferForm disabled={isSold} />}
116+
{!isSold && <OfferForm disabled={isSold} listingId={listing._id} />}
117117
<VehicleAdvDetails vehicle={listing.vehicle} />
118118
<div className={styles.spacer} />
119119
<ListingsCarousel

pages/messages/components/ChatList.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { BaseButton, Loader, Button } from '../../../components'
1414
import { getUsername } from '../../../utils/helpers'
1515
import styles from './ChatList.module.scss'
1616
import ChatAvatar from './ChatAvatar'
17+
import { getMessage } from './chatUtils'
1718

1819
type Props = {
1920
onPaginate: () => void
@@ -60,7 +61,9 @@ const ChatList: React.FunctionComponent<Props> = ({ onPaginate }) => {
6061
{get(chat, 'lastMessage.userId') === currentUser._id && (
6162
<FiCornerDownRight />
6263
)}
63-
<span>{get(chat, 'lastMessage.text', '')}</span>
64+
<span>
65+
{get(chat, 'lastMessage') && getMessage(chat.lastMessage)}
66+
</span>
6467
</section>
6568
{unreads > 0 && (
6669
<span className={styles.unreadsBubble}>{unreads}</span>

pages/messages/components/MessagesList.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
align-self: flex-start;
4545
color: $color-dark;
4646
}
47+
&.unstyledMessage {
48+
background-color: transparent;
49+
box-shadow: unset;
50+
color: $color-red;
51+
padding: 0;
52+
font-weight: $font-weight-medium;
53+
font-family: $font-family;
54+
}
4755
}
4856
}
4957
}

0 commit comments

Comments
 (0)