diff --git a/api/server.ts b/api/server.ts index 0fcecda..e84a2ac 100644 --- a/api/server.ts +++ b/api/server.ts @@ -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], @@ -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) }) diff --git a/package-lock.json b/package-lock.json index faf27a3..32c4288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "foodmarket", + "name": "skaff", "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "foodmarket", + "name": "skaff", "version": "1.0.0", "dependencies": { "@expo/webpack-config": "^18.0.1", diff --git a/src/components/TenderRequest.tsx b/src/components/TenderRequest.tsx index 33d1700..0368b16 100644 --- a/src/components/TenderRequest.tsx +++ b/src/components/TenderRequest.tsx @@ -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' @@ -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( @@ -256,68 +267,108 @@ const TenderRequest = ({ Matchande anbud {validOffers.map((offer, i) => ( - navigation.navigate('TenderRequest', { id })} - > - { - if (offer.approved) - return ( - - - + navigation.navigate('TenderRequest', { id })} + > + { + if (offer.approved) + return ( + - Tilldelad - - + + + Tilldelad + + + ) + else if ( + offers.filter((offer) => offer.approved).length < + 1 ) - else if ( - offers.filter((offer) => offer.approved).length < 1 - ) - return ( + return ( + + ) + }} + /> + {offer.acceptanceMotivation && ( + + Acceptance reason: {offer.acceptanceMotivation} + + )} + + + + + + Motivation to choose {offer.buyer.name}'s offer:{' '} + + setAcceptanceMotivationText(text)} + /> + + - ) - }} - /> - + + + + + ))} + Ej uppfyllda anbud @@ -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, + } }) diff --git a/src/data/offers.ts b/src/data/offers.ts index 72824bb..8601ceb 100644 --- a/src/data/offers.ts +++ b/src/data/offers.ts @@ -9,6 +9,7 @@ export type Offer = { buyer: Buyer supplier: Supplier approved: boolean + acceptanceMotivation: string submissionDate: Date submitted: boolean tenderRequestId: string