Skip to content

Commit

Permalink
feat: added device id for syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
iRaySpace committed May 10, 2019
1 parent 0ec59db commit 8276e45
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 19 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@
- Cancel Order on view order (no take-away option)

# v1.2.7 [10 мая 2019]
- Fix on protocol in syncing
- Fix on protocol in syncing
- Added Device Id field
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tailpos",
"version": "1.2.6",
"version": "1.2.7",
"private": true,
"devDependencies": {
"babel-eslint": "8.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function() {

retrieveSettings().then(item => {
if (item) {
stores.stateStore.setDeviceId(item.deviceId);
stores.stateStore.setQueueHost(item.queueHost);
if (item.hasTailOrder) {
stores.stateStore.toggleTailOrder();
Expand Down
25 changes: 8 additions & 17 deletions src/container/SettingsContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BluetoothSerial from "react-native-bluetooth-serial";
import { BluetoothStatus } from "react-native-bluetooth-status";
import Settings from "@screens/Settings";
import { syncObjectValues } from "../../store/PosStore/syncInBackground";
import { saveToSettings } from "../../services/storage";
import { saveConfig } from "../../services/storage";

// import { syncData } from "./sync";

Expand Down Expand Up @@ -663,11 +663,10 @@ export default class SettingsContainer extends React.Component {
password: this.props.stateStore.settings_state[0].password,
});
}
// this.setState({
// syncEditStatus: false,
// });
saveConfig(this.props.stateStore);
this.props.stateStore.changeValue("syncEditStatus", false, "Settings");
};

onAddRoles(values) {
this.props.roleStore.add({
role: values.role,
Expand All @@ -676,6 +675,7 @@ export default class SettingsContainer extends React.Component {
canLogin: values.checkBoxValue,
});
}

onDeleteRoles = values => {
Alert.alert(
"Delete attendant", // title
Expand Down Expand Up @@ -709,20 +709,9 @@ export default class SettingsContainer extends React.Component {
}

onQueueSave = () => {
const {
setQueueNotEditing,
queueHost,
hasTailOrder,
useDefaultCustomer,
useDescription,
} = this.props.stateStore;
const { setQueueNotEditing } = this.props.stateStore;

saveToSettings({
queueHost,
hasTailOrder,
useDescription,
useDefaultCustomer,
});
saveConfig(this.props.stateStore);
setQueueNotEditing();
};

Expand Down Expand Up @@ -827,6 +816,8 @@ export default class SettingsContainer extends React.Component {
isSyncing={stateStore.isSyncing}
isHttps={stateStore.isHttps}
toggleHttps={stateStore.toggleHttps}
deviceId={stateStore.deviceId}
setDeviceId={stateStore.setDeviceId}
/>
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ export const saveToSettings = value => {
const valueString = JSON.stringify(value);
return AsyncStorage.setItem("@Settings:Queue", valueString);
};

export const saveConfig = settings => {
return saveToSettings({
deviceId: settings.deviceId,
queueHost: settings.queueHost,
hasTailOrder: settings.hasTailOrder,
useDescription: settings.useDescription,
useDefaultCustomer: settings.useDefaultCustomer,
});
};
1 change: 1 addition & 0 deletions src/store/PosStore/DbFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function sync(jsonObject, type, trashObj, credentials, jobStatus) {
{
tailposData: JSON.parse(jsonObject),
trashObject: JSON.parse(trashObj),
deviceId: credentials.deviceId,
typeOfSync: type,
},
);
Expand Down
1 change: 1 addition & 0 deletions src/store/PosStore/syncInBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function syncObjectValues(status, store, jobStatus) {
) {
const protocol = store.stateStore.isHttps ? "https://" : "http://";
const syncInfo = {
deviceId: store.stateStore.deviceId,
url: protocol + store.printerStore.sync[0].url,
user_name: store.printerStore.sync[0].user_name,
password: store.printerStore.sync[0].password,
Expand Down
4 changes: 4 additions & 0 deletions src/store/StateStore/StateStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const StateStore = types
isEditingQueue: types.optional(types.boolean, false),
useDescription: types.optional(types.boolean, false),
isHttps: types.optional(types.boolean, false),
deviceId: types.optional(types.string, ""),

// Is Syncing
isSyncing: types.optional(types.boolean, false),
Expand Down Expand Up @@ -170,6 +171,9 @@ const StateStore = types
toggleHttps() {
self.isHttps = !self.isHttps;
},
setDeviceId(deviceId) {
self.deviceId = deviceId;
},
}));

const Store = StateStore.create({});
Expand Down
10 changes: 10 additions & 0 deletions src/stories/components/SyncComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class CompanyComponent extends React.PureComponent {
isSyncing,
isHttps,
toggleIsHttps,
setDeviceId,
deviceId,
} = this.props;

const SyncStatus = isSyncing ? (
Expand Down Expand Up @@ -112,6 +114,14 @@ class CompanyComponent extends React.PureComponent {
placeholder="Password"
label="Password"
/>
<EditInput
secure={false}
value={deviceId}
disabled={!syncEditStatus}
onChange={setDeviceId}
placeholder="xxxxxxxx"
label="Device ID"
/>
<CardItem>{this.renderSyncButtons()}</CardItem>
</Card>
</View>
Expand Down
4 changes: 4 additions & 0 deletions src/stories/screens/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Settings extends React.Component {

// Sync
isSyncing,
setDeviceId,
deviceId,

// navigation
navigation,
Expand Down Expand Up @@ -215,6 +217,8 @@ class Settings extends React.Component {
password={password}
isHttps={isHttps}
toggleIsHttps={toggleHttps}
deviceId={deviceId}
setDeviceId={setDeviceId}
/>
);
}
Expand Down

0 comments on commit 8276e45

Please sign in to comment.