Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiloysss committed Feb 5, 2019
1 parent 5d99bf1 commit 68ec3be
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 36 deletions.
110 changes: 74 additions & 36 deletions src/container/SettingsContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,39 @@ export default class SettingsContainer extends React.Component {
if (values.confirmPin) {
if (values.pin === values.confirmPin) {
if (values.status === "Save Attendant") {
this.props.attendantStore.add({
user_name: values.attendantName,
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission: parseInt(values.commission, 10),
dateUpdated: Date.now(),
syncStatus: false,
});
Toast.show({
text: "Successfully Added Attendant",
duration: 5000,
});
this.setState({
attendants: this.props.attendantStore.rows.slice(),
attendantsInfo: {},
});
this.props.attendantStore
.findAttendant(values.attendantName)
.then(result => {
if (!result) {
this.props.attendantStore.add({
user_name: values.attendantName,
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission:
parseInt(values.commission, 10) > 0
? parseInt(values.commission, 10)
: 0,
dateUpdated: Date.now(),
syncStatus: false,
});
Toast.show({
text: "Successfully Added Attendant",
duration: 5000,
});
this.setState({
attendants: this.props.attendantStore.rows.slice(),
attendantsInfo: {},
});
} else {
Toast.show({
text: "Attendant Already Exist",
type: "danger",
duration: 5000,
});
}
});

// this.props.stateStore.changeValue("attendants", JSON.stringify(this.props.attendantStore.rows.slice()), "Settings")
// this.props.stateStore.changeValue("attendantsInfo",{}, "Settings")
} else if (values.status === "Edit Attendant") {
Expand All @@ -450,7 +466,10 @@ export default class SettingsContainer extends React.Component {
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission: parseInt(values.commission, 10),
commission:
parseInt(values.commission, 10) > 0
? parseInt(values.commission, 10)
: 0,

dateUpdated: Date.now(),
syncStatus: false,
Expand Down Expand Up @@ -519,23 +538,39 @@ export default class SettingsContainer extends React.Component {
}
} else {
if (values.status === "Save Attendant") {
this.props.attendantStore.add({
user_name: values.attendantName,
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission: parseInt(values.commission, 10),
dateUpdated: Date.now(),
syncStatus: false,
});
Toast.show({
text: "Successfully Added Attendant",
duration: 5000,
});
this.setState({
attendants: this.props.attendantStore.rows.slice(),
attendantsInfo: {},
});
this.props.attendantStore
.findAttendant(values.attendantName)
.then(result => {
if (!result) {
this.props.attendantStore.add({
user_name: values.attendantName,
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission:
parseInt(values.commission, 10) > 0
? parseInt(values.commission, 10)
: 0,
dateUpdated: Date.now(),
syncStatus: false,
});
Toast.show({
text: "Successfully Added Attendant",
duration: 5000,
});
this.setState({
attendants: this.props.attendantStore.rows.slice(),
attendantsInfo: {},
});
} else {
Toast.show({
text: "Attendant Already Exist",
type: "danger",
duration: 5000,
});
}
});

// this.props.stateStore.changeValue("attendants", JSON.stringify(this.props.attendantStore.rows.slice()), "Settings")
// this.props.stateStore.changeValue("attendantsInfo",{}, "Settings")
} else if (values.status === "Edit Attendant") {
Expand All @@ -549,7 +584,10 @@ export default class SettingsContainer extends React.Component {
pin_code: values.pin,
role: values.role,
canLogin: values.canLogin,
commission: parseInt(values.commission, 10),
commission:
parseInt(values.commission, 10) > 0
? parseInt(values.commission, 10)
: 0,

dateUpdated: Date.now(),
syncStatus: false,
Expand Down
17 changes: 17 additions & 0 deletions src/store/PosStore/AttendantStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ const AttendantStore = types
}
});
},
findAttendant(name) {
return new Promise(function(resolve, reject) {
db
.find({
selector: {
user_name: { $regex: `.*${name}.*` },
},
})
.then(result => {
if (result.docs.length > 0) {
resolve(true);
} else {
resolve(false);
}
});
});
},
}));

const Store = AttendantStore.create({});
Expand Down

0 comments on commit 68ec3be

Please sign in to comment.