Skip to content

Commit

Permalink
Feat/bid acceptance motivation (#1)
Browse files Browse the repository at this point in the history
* Add acceptance offer motivation modal

* Send notifications to everyone who bid

* Format fix
  • Loading branch information
luciadabezies authored Jul 5, 2024
1 parent 115599a commit c43a356
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 53 deletions.
21 changes: 20 additions & 1 deletion api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ io.on('connection', (socket) => {
const tenderRequest = state.tenderRequests.find(
(tr) => tr.id === offer.tenderRequestId
)
const otherOffersForTender = state.offers.filter(
(o) => o.tenderRequestId === tenderRequest?.id && offer.id !== o.id
)
if (tenderRequest)
sendPushNotification({
to: [token],
Expand All @@ -254,7 +257,23 @@ io.on('connection', (socket) => {
tenderRequestId: offer.tenderRequestId,
},
})
}

if (tenderRequest && otherOffersForTender)
otherOffersForTender.forEach(o =>
sendPushNotification({
to: [o.supplier.token],
title: 'Anbud förkastat',
body: `Ditt bud på ${tenderRequest.title} har förkastats. ${offer.supplier.name}s bud har godkänts av följande skäl: ${offer.acceptanceMotivation}`,
data: {
date: new Date(),
type: 'offer',
to: [o.supplier.id],
id: offer.id,
tenderRequestId: tenderRequest?.id,
},
})
)
}
state.offers[index] = offer
io.emit('offers', state.offers)
})
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

187 changes: 137 additions & 50 deletions src/components/TenderRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import {
List,
Avatar,
} from 'react-native-paper'
import { ScrollView, StyleSheet, View } from 'react-native'
import {
Modal,
ScrollView,
StyleSheet,
TextInput,
TouchableOpacity,
View,
} from 'react-native'
import { Tabs, TabScreen } from 'react-native-paper-tabs'
import Chat from './Chat'
import useTenderRequests from '../hooks/useTenderRequests'
Expand Down Expand Up @@ -45,6 +52,10 @@ const TenderRequest = ({
const { user } = useAuth()
const [offers, updateOffer, , refreshOffers] = useOffers()

const [showModal, setShowModal] = useState(false)
const [acceptanceMotivationText, setAcceptanceMotivationText] = useState("");


useEffect(() => {
if (route.params.tenderRequestId) {
const tenderRequestFromState = tenderRequests.find(
Expand Down Expand Up @@ -256,68 +267,108 @@ const TenderRequest = ({
<Container>
<Subheading>Matchande anbud</Subheading>
{validOffers.map((offer, i) => (
<Card
key={i}
style={styles.card}
// onPress={() => navigation.navigate('TenderRequest', { id })}
>
<Card.Title
titleVariant="titleSmall"
titleStyle={{
fontSize: 14,
}}
title={
offer.price.SEK + ' kr från: ' + offer.supplier?.name
}
subtitle={
'Inkom ' +
offer.submissionDate?.toString().split('T')[0]
}
right={(props) => {
if (offer.approved)
return (
<Container
style={{
flexDirection: 'row',
display: 'flex',
}}
>
<MaterialCommunityIcons
size={25}
name="clipboard-check"
/>
<Text
<View>
<Card
key={i}
style={styles.card}
// onPress={() => navigation.navigate('TenderRequest', { id })}
>
<Card.Title
titleVariant="titleSmall"
titleStyle={{
fontSize: 14,
}}
title={
offer.price.SEK +
' kr från: ' +
offer.supplier?.name
}
subtitle={
'Inkom ' +
offer.submissionDate?.toString().split('T')[0]
}
right={(props) => {
if (offer.approved)
return (
<Container
style={{
marginLeft: 5,
marginTop: 5,
flexDirection: 'row',
display: 'flex',
}}
>
Tilldelad
</Text>
</Container>
<MaterialCommunityIcons
size={25}
name="clipboard-check"
/>
<Text
style={{
marginLeft: 5,
marginTop: 5,
}}
>
Tilldelad
</Text>
</Container>
)
else if (
offers.filter((offer) => offer.approved).length <
1
)
else if (
offers.filter((offer) => offer.approved).length < 1
)
return (
return (
<Button
icon="clipboard-check"
mode="contained"
uppercase={false}
style={{ marginRight: 10 }}
onPress={() => {
setShowModal(true)
}}
>
Tilldela
</Button>
)
}}
/>
{offer.acceptanceMotivation && (
<View style={styles.acceptanceReasonTextWrapper}>
<Text style={styles.acceptanceReasonText}>Acceptance reason: {offer.acceptanceMotivation}</Text>
</View>
)}
</Card>
<Modal visible={showModal} transparent={true}>
<View style={styles.centerView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>
Motivation to choose {offer.buyer.name}'s offer:{' '}
</Text>
<TextInput
style={styles.modalInput}
multiline={true}
onChangeText={text => setAcceptanceMotivationText(text)}
/>
<Container style={styles.modalButtons}>
<Button onPress={() => setShowModal(false)}>
Cancel
</Button>
<Button
icon="clipboard-check"
mode="contained"
uppercase={false}
style={{ marginRight: 10 }}
onPress={() => {
console.log('offer', offer)
updateOffer({ ...offer, approved: true })
console.log('motivation text', acceptanceMotivationText)
updateOffer({ ...offer, acceptanceMotivation: acceptanceMotivationText, approved: true })
setShowModal(false)
}}
>
Tilldela
Accept
</Button>
)
}}
/>
</Card>
</Container>
</View>
</View>
</Modal>
</View>
))}
</Container>

<Container>
<Divider />
<Subheading>Ej uppfyllda anbud</Subheading>
Expand Down Expand Up @@ -368,4 +419,40 @@ const styles = StyleSheet.create({
marginBottom: 5,
backgroundColor: 'white',
},
centerView: {
backgroundColor: 'rgba(0,0,0,0.5)',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalView: {
backgroundColor: 'white',
marginHorizontal: 20,
padding: 35,
borderRadius: 4,
},
modalText: {
fontSize: 16,
marginBottom: 12,
},
modalInput: {
height: 120,
textAlignVertical: 'top',
margin: 12,
borderWidth: 0.3,
padding: 10,
borderRadius: 4,
},
modalButtons: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
},
acceptanceReasonTextWrapper: {
paddingHorizontal: 12,
paddingBottom: 12
},
acceptanceReasonText: {
fontSize: 12,
}
})
1 change: 1 addition & 0 deletions src/data/offers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Offer = {
buyer: Buyer
supplier: Supplier
approved: boolean
acceptanceMotivation: string
submissionDate: Date
submitted: boolean
tenderRequestId: string
Expand Down

0 comments on commit c43a356

Please sign in to comment.