Skip to content

Commit 22f21b7

Browse files
authored
Merge pull request #77 from iRaySpace/master
refactor: componetize; feat: added new payment types
2 parents ce7b103 + 4d71b68 commit 22f21b7

File tree

7 files changed

+250
-192
lines changed

7 files changed

+250
-192
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default class PaymentController {
2+
constructor(stateStore) {
3+
this.stateStore = stateStore;
4+
}
5+
modalVisibleChange = modalVisible => {
6+
this.stateStore.changeValue("modalVisible", modalVisible, "Payment");
7+
};
8+
onChangePayment = payment => {
9+
this.stateStore.changeValue("selected", payment, "Payment");
10+
};
11+
onChangeCustomerName = customerName => {
12+
this.stateStore.changeValue("customerName", customerName, "Payment");
13+
};
14+
onChangeCustomerEmail = customerEmail => {
15+
this.stateStore.changeValue("customerEmail", customerEmail, "Payment");
16+
};
17+
onChangeCustomerPhoneNumber = customerPhoneNumber => {
18+
this.stateStore.changeValue(
19+
"customerPhoneNumber",
20+
customerPhoneNumber,
21+
"Payment",
22+
);
23+
};
24+
onChangeCustomerNotes = customerNotes => {
25+
this.stateStore.changeValue("customerNotes", customerNotes, "Payment");
26+
};
27+
}

src/container/PaymentContainer/index.js

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import * as EmailValidator from "email-validator";
99
import { inject, observer } from "mobx-react/native";
1010
import { currentLanguage } from "../../translations/CurrentLanguage";
1111

12+
import PaymentController from "./controller";
1213
import PaymentScreen from "@screens/Payment";
14+
1315
import translation from "../../translations/translation";
1416
import LocalizedStrings from "react-native-localization";
1517
let strings = new LocalizedStrings(translation);
18+
1619
const moment = require("moment");
20+
1721
@inject(
1822
"itemStore",
1923
"customerStore",
@@ -30,9 +34,8 @@ const moment = require("moment");
3034
export default class PaymentContainer extends React.Component {
3135
constructor(props) {
3236
super(props);
33-
this.state = {
34-
arrayObjects: [],
35-
};
37+
this.controller = new PaymentController(props.stateStore);
38+
this.state = { arrayObjects: [] };
3639
}
3740

3841
componentWillMount() {
@@ -120,7 +123,7 @@ export default class PaymentContainer extends React.Component {
120123
}
121124
}
122125

123-
onValueChange(text) {
126+
onValueChange = text => {
124127
if (text === "Del") {
125128
const finalValue = this.props.stateStore.payment_value.slice(0, -1);
126129
this.props.stateStore.setPaymentValue(finalValue);
@@ -137,7 +140,7 @@ export default class PaymentContainer extends React.Component {
137140
}
138141
}
139142
}
140-
}
143+
};
141144

142145
setOrderCompleted() {
143146
const {
@@ -984,21 +987,26 @@ export default class PaymentContainer extends React.Component {
984987
this.props.navigation.goBack();
985988
}
986989

987-
onPrinterChange(value) {
988-
this.props.stateStore.changeValue("itemSelected", value, "Payment");
989-
BluetoothSerial.connect("DC:0D:30:0B:77:B1")
990-
.then(res => {
991-
this.props.stateStore.changeValue("connection", true, "Payment");
992-
})
993-
.catch(() => {
994-
// this.setState({ connection: false });
995-
this.props.stateStore.changeValue("connection", false, "Payment");
996-
});
997-
}
998-
999-
onPrinterPress() {
990+
navigation = () => {
991+
this.getBluetoothState(true);
992+
this.onBack();
993+
};
994+
// DEPRECATED
995+
// onPrinterChange(value) {
996+
// this.props.stateStore.changeValue("itemSelected", value, "Payment");
997+
// BluetoothSerial.connect("DC:0D:30:0B:77:B1")
998+
// .then(res => {
999+
// this.props.stateStore.changeValue("connection", true, "Payment");
1000+
// })
1001+
// .catch(() => {
1002+
// // this.setState({ connection: false });
1003+
// this.props.stateStore.changeValue("connection", false, "Payment");
1004+
// });
1005+
// }
1006+
1007+
onPrinterPress = () => {
10001008
this.props.navigation.navigate("Settings");
1001-
}
1009+
};
10021010

10031011
onConnectDevice() {
10041012
if (this.props.printerStore.rows.length > 0) {
@@ -1075,7 +1083,8 @@ export default class PaymentContainer extends React.Component {
10751083
});
10761084
}
10771085
}
1078-
searchCustomer(text) {
1086+
1087+
searchCustomer = text => {
10791088
this.props.customerStore.search(text).then(result => {
10801089
for (let i = 0; i < result.length; i += 1) {
10811090
let existing = false;
@@ -1089,8 +1098,9 @@ export default class PaymentContainer extends React.Component {
10891098
}
10901099
}
10911100
});
1092-
}
1093-
onSaveCustomer() {
1101+
};
1102+
1103+
onSaveCustomer = () => {
10941104
if (this.props.stateStore.payment_state[0].customerName) {
10951105
if (
10961106
EmailValidator.validate(
@@ -1115,14 +1125,15 @@ export default class PaymentContainer extends React.Component {
11151125
} else {
11161126
Alert.alert(strings.InvalidEmail, strings.PleaseEnterValidEmail);
11171127
}
1118-
}
1119-
onCancelAddCustomer() {
1128+
};
1129+
1130+
onCancelAddCustomer = () => {
11201131
this.props.stateStore.changeValue("modalVisible", false, "Payment");
11211132
this.props.stateStore.changeValue("customerName", "", "Payment");
11221133
this.props.stateStore.changeValue("customerEmail", "", "Payment");
11231134
this.props.stateStore.changeValue("customerPhoneNumber", "", "Payment");
11241135
this.props.stateStore.changeValue("customerNotes", "", "Payment");
1125-
}
1136+
};
11261137

11271138
render() {
11281139
strings.setLanguage(currentLanguage().companyLanguage);
@@ -1131,49 +1142,27 @@ export default class PaymentContainer extends React.Component {
11311142
values={this.props.stateStore.payment_state[0].toJSON()}
11321143
paymentValue={this.props.stateStore.payment_value}
11331144
amountDue={this.props.stateStore.amount_due}
1134-
// value={this.props.stateStore.payment_value}
1135-
// modalVisible={this.props.stateStore.payment_state[0].modalVisible}
11361145
name={this.props.stateStore.payment_state[0].customerName}
1137-
connectDevice={() => this.onConnectDevice()}
1138-
onPickerChange={text =>
1139-
this.props.stateStore.changeValue("selected", text, "Payment")
1140-
}
1141-
onValueChange={this.onValueChange.bind(this)}
1146+
connectDevice={this.onConnectDevice}
1147+
onValueChange={this.onValueChange}
11421148
defaultCustomer={
11431149
this.props.receiptStore.defaultCustomer.name.toString()
11441150
? this.props.receiptStore.defaultCustomer.name.toString()
11451151
: "Default customer"
11461152
}
11471153
onPay={this.onPay}
1148-
onPrinterChange={value => this.onPrinterChange(value)}
1149-
searchCustomer={text => this.searchCustomer(text)}
1154+
searchCustomer={this.searchCustomer}
11501155
searchedCustomers={this.state.arrayObjects}
1151-
modalVisibleChange={text =>
1152-
this.props.stateStore.changeValue("modalVisible", text, "Payment")
1153-
}
1154-
navigation={() => {
1155-
this.getBluetoothState(true);
1156-
this.onBack();
1157-
}}
1158-
onPrinterPress={() => this.onPrinterPress()}
1159-
onChangeaCustomerName={text =>
1160-
this.props.stateStore.changeValue("customerName", text, "Payment")
1161-
}
1162-
onChangeCustomerEmail={text =>
1163-
this.props.stateStore.changeValue("customerEmail", text, "Payment")
1164-
}
1165-
onChangeCustomerPhoneNumber={text =>
1166-
this.props.stateStore.changeValue(
1167-
"customerPhoneNumber",
1168-
text,
1169-
"Payment",
1170-
)
1171-
}
1172-
onChangeCustomerNotes={text =>
1173-
this.props.stateStore.changeValue("customerNotes", text, "Payment")
1174-
}
1175-
onSaveCustomer={() => this.onSaveCustomer()}
1176-
onCancelAddCustomer={() => this.onCancelAddCustomer()}
1156+
modalVisibleChange={this.controller.modalVisibleChange}
1157+
navigation={this.navigation}
1158+
onPrinterPress={this.onPrinterPress}
1159+
onChangePayment={this.controller.onChangePayment}
1160+
onChangeCustomerName={this.controller.onChangeCustomerName}
1161+
onChangeCustomerEmail={this.controller.onChangeCustomerEmail}
1162+
onChangeCustomerPhoneNumber={this.onChangeCustomerPhoneNumber}
1163+
onChangeCustomerNotes={this.controller.onChangeCustomerNotes}
1164+
onSaveCustomer={this.onSaveCustomer}
1165+
onCancelAddCustomer={this.onCancelAddCustomer}
11771166
currency={
11781167
this.props.printerStore.companySettings[0].countryCode
11791168
? this.props.printerStore.companySettings[0].countryCode

src/store/PosStore/PaymentStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Payment = types
2121
date: types.Date,
2222
receipt: types.string,
2323
paid: types.number,
24-
type: types.enumeration("Type", ["Cash", "Card"]),
24+
type: types.enumeration("Type", ["Cash", "Card", "Visa", "Amex", "Sapn"]),
2525
deviceId: types.optional(types.string, DeviceInfo.getDeviceId()),
2626
dateUpdated: types.optional(types.Date, Date.now),
2727
syncStatus: types.optional(types.boolean, false),

0 commit comments

Comments
 (0)