Skip to content

Commit c99a6bb

Browse files
authored
Merge pull request #2 from BuildFire/create-controllers
fix(ui-issues): fix safe area issue, fix console error
2 parents 434a764 + f7247a0 commit c99a6bb

File tree

11 files changed

+107
-27
lines changed

11 files changed

+107
-27
lines changed

control/content/js/contentController.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const contentController = {
3939
const { settingData, isNewInstance } = await Settings.get();
4040
contentState.settings = settingData;
4141
if (isNewInstance) {
42+
await Settings.save(contentState.settings);
4243
await UserCodeSequences.initializeCodeSequence();
4344
await AnalyticsManager.init();
4445
}

control/transaction/js/tableController.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const searchTableConfig = {
77
},
88
columns: [{
99
header: 'Date',
10-
data: '<span class=\'margin-bottom-five\'>${data.date}</span>',
10+
data: '<span class=\'margin-bottom-five\'>${TransactionController.formatDate(data.createdOn)}</span>',
1111
type: 'string',
12-
width: '100px',
12+
width: '165px',
1313
sortBy: 'date1',
1414
defaultSorted: true,
1515
}, {
@@ -21,18 +21,18 @@ const searchTableConfig = {
2121
header: 'Stamps',
2222
data: '<span class=\'margin-bottom-five\'>${data.changeValue}</span>',
2323
type: 'string',
24-
width: '100px',
24+
width: '90px',
2525
}, {
2626
header: 'Rewards',
2727
data: '<span class=\'margin-bottom-five\'>${TransactionController.getRewards(data)}</span>',
2828
type: 'string',
29-
width: '100px',
29+
width: '90px',
3030
},
3131
{
3232
header: 'Redeems',
3333
data: '<span class=\'margin-bottom-five\'>${TransactionController.getRedeems(data)}</span>',
3434
type: 'string',
35-
width: '100px',
35+
width: '90px',
3636
},
3737
{
3838
header: 'Authorized by',
@@ -131,6 +131,23 @@ const TransactionController = {
131131

132132
return 0;
133133
},
134+
formatDate(dateString) {
135+
console.log('dateString:', dateString);
136+
const date = new Date(dateString);
137+
138+
const month = date.getMonth() + 1;
139+
const day = date.getDate();
140+
const year = date.getFullYear();
141+
142+
let hours = date.getHours();
143+
const minutes = date.getMinutes();
144+
145+
const ampm = hours >= 12 ? 'PM' : 'AM';
146+
hours = hours % 12 || 12;
147+
148+
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
149+
return `${month}/${day}/${year}, ${hours}:${formattedMinutes} ${ampm}`;
150+
},
134151

135152
init() {
136153
this.transactionsTable = new SearchTable('transactionTableContainer', searchTableConfig);

resources/languages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@
227227
"defaultValue": "Scanner works only on devices.",
228228
"required": true,
229229
"inputType": "text"
230+
},
231+
"networkError": {
232+
"title": "Check connection and retry.",
233+
"placeholder": "Check connection and retry.",
234+
"maxLength": 80,
235+
"defaultValue": "Check connection and retry.",
236+
"required": true,
237+
"inputType": "text"
238+
},
239+
"cameraPermissionRequired": {
240+
"title": "Camera permission required.",
241+
"placeholder": "Access to the camera has been prohibited, please enable it in the settings app to continue",
242+
"maxLength": 80,
243+
"defaultValue": "Access to the camera has been prohibited, please enable it in the settings app to continue",
244+
"required": true,
245+
"inputType": "text"
230246
}
231247
}
232248
},

widget/global/js/repositories/Settings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Settings {
1818
if (err) return reject(err);
1919
if (!res || !res.data || !Object.keys(res.data).length) {
2020
const data = new Setting().toJSON();
21-
Settings.save(data);
2221
resolve({ settingData: data, isNewInstance: true });
2322
} else {
2423
const data = new Setting(res.data).toJSON();

widget/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h4 class="dialog-userid-title" bfString="general.enterUserId"></h4>
8585
<label class="mdc-text-field mdc-text-field--filled">
8686
<span class="mdc-text-field__ripple"></span>
8787
<span class="mdc-floating-label hint-text" id="userId" bfString="general.userId"></span>
88-
<input id="userIdField" class="mdc-text-field__input" type="number" aria-labelledby="userId">
88+
<input id="userIdField" class="mdc-text-field__input" type="number" inputmode="decimal" aria-labelledby="userId">
8989
<span class="mdc-line-ripple"></span>
9090
</label>
9191
<span id="userIdError" class="userid-error"></span>

widget/js/pages/customer/CustomerView.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ const CustomerView = {
116116
this._initRewardList(availbleRewardLength);
117117
this._updateConfirmButton();
118118
},
119-
_addNewTransaction() {
119+
async _addNewTransaction() {
120120
try {
121+
if (!navigator.onLine) {
122+
buildfire.dialog.toast({
123+
message: await getLanguage('general.networkError'),
124+
});
125+
return;
126+
}
121127
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
122128
this._uiElement.confirmTransactionBtn.disabled = true;
123129

@@ -342,6 +348,11 @@ const CustomerView = {
342348
availableRewardList.appendChild(emptyState);
343349
}
344350
},
351+
refreshRewardList() {
352+
let availbleRewardLength = CustomerController.getAvailbleRewardLength(this.newStamps, widgetAppState.currentCustomer.currentStamps, widgetAppState.settings.cardSize);
353+
availbleRewardLength += widgetAppState.currentCustomer.availableRewards.length;
354+
this._initRewardList(availbleRewardLength);
355+
},
345356

346357
_createCheckbox(index) {
347358
const template = document.getElementById('template');

widget/js/pages/employee/EmployeeView.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const EmployeeView = {
1717

1818
const formFab = new buildfire.components.fabSpeedDial('#fabSpeedDialContainer', formOptions);
1919
const scannerFab = new buildfire.components.fabSpeedDial('#fabSpeedDialContainer', scannerOptions);
20-
scannerFab.onMainButtonClick = () => this._openScanner();
20+
scannerFab.onMainButtonClick = () => this._openScanner(true, true);
2121
formFab.onMainButtonClick = () => this._openMaterialForm();
2222
},
2323

@@ -35,6 +35,12 @@ const EmployeeView = {
3535
});
3636

3737
confirmBtn.addEventListener('click', async () => {
38+
if (!navigator.onLine) {
39+
buildfire.dialog.toast({
40+
message: await getLanguage('general.networkError'),
41+
});
42+
return;
43+
}
3844
const userId = document.getElementById('userIdField').value;
3945
if (!userId) {
4046
userIdError.innerText = await getLanguage('general.userIdRequired');
@@ -63,7 +69,7 @@ const EmployeeView = {
6369
document.getElementById('userIdField').value = '';
6470
});
6571
},
66-
_openScanner(showDeviceOnlyMessage = true) {
72+
async _openScanner(showDeviceOnlyMessage = true, showCameraPermissionMessage = false) {
6773
const isWeb = buildfire.getContext().device.platform === 'web';
6874
if (isWeb) {
6975
if (!showDeviceOnlyMessage) return null;
@@ -75,14 +81,29 @@ const EmployeeView = {
7581

7682
return null;
7783
}
84+
7885
buildfire.services.camera.barcodeScanner.scan(
7986
{
8087
preferFrontCamera: false,
8188
showFlipCameraButton: false,
8289
formats: 'QR_CODE',
8390
},
8491
async (err, result) => {
85-
if (err) return console.error(err);
92+
if (err) {
93+
if (JSON.stringify(err) === '"Scanning failed: Access to the camera has been prohibited; please enable it in the Settings app to continue"') {
94+
if (showCameraPermissionMessage) {
95+
const permissionErrorMessage = await getLanguage('general.cameraPermissionRequired');
96+
buildfire.dialog.toast({
97+
message: permissionErrorMessage,
98+
type: 'danger',
99+
});
100+
}
101+
} else {
102+
buildfire.dialog.toast({ message: err, type: 'danger' });
103+
}
104+
return console.error(err);
105+
}
106+
86107
if (result.cancelled) {
87108
return null;
88109
}
@@ -127,7 +148,7 @@ const EmployeeView = {
127148
async _openCustomerProfile(userId) {
128149
try {
129150
const result = await CustomerController.getCustomerInfo(userId, widgetAppState.settings.cardSize);
130-
if (result.currentStamps) {
151+
if (result.currentStamps !== undefined) {
131152
widgetAppState.currentCustomer.currentStamps = result.currentStamps;
132153
widgetAppState.currentCustomer.availableRewards = result.availableRewards;
133154
}

widget/js/utils/handleCPSync.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ const handleCPSync = {
1212
if (data.data.content || data.data.content === '') {
1313
widgetAppState.settings.introductionWYSIWYG = data.data.content;
1414
}
15-
if (widgetAppRouter.currentPage) return;
15+
if (AuthManager.isEmployee) {
16+
if (widgetAppRouter.currentPage !== 'home') return;
17+
} else if (widgetAppRouter.currentPage) return;
1618
CustomerView._initListView();
1719
CustomerView._initValues();
1820
} else if (data.cmd === 'cardChanged') {
1921
if (data.data.cardSize) {
2022
widgetAppState.settings.cardSize = data.data.cardSize;
2123
const result = await CustomerController.getCustomerInfo(widgetAppState.currentCustomer.friendlyId,
2224
widgetAppState.settings.cardSize);
23-
if (result.currentStamps) {
25+
if (result.currentStamps !== undefined) {
2426
widgetAppState.currentCustomer.currentStamps = result.currentStamps;
2527
widgetAppState.currentCustomer.availableRewards = result.availableRewards;
2628
}
@@ -32,14 +34,18 @@ const handleCPSync = {
3234
widgetAppState.currentCustomer.imageUrl = user?.imageUrl ? user.imageUrl : 'https://app.buildfire.com/app/media/avatar.png';
3335
}
3436

35-
if (widgetAppRouter.currentPage) return;
37+
if (AuthManager.isEmployee) {
38+
if (widgetAppRouter.currentPage !== 'home') return;
39+
} else if (widgetAppRouter.currentPage) return;
3640
CustomerView.drawStamps(widgetAppState.settings.cardSize);
3741
if (AuthManager.isEmployee) {
38-
CustomerView._initRewardList();
42+
CustomerView.refreshRewardList();
3943
}
4044
} else if (data.cmd === 'designChanged') {
4145
widgetAppState.settings.design = data.data.design;
42-
if (widgetAppRouter.currentPage) return;
46+
if (AuthManager.isEmployee) {
47+
if (widgetAppRouter.currentPage !== 'home') return;
48+
} else if (widgetAppRouter.currentPage) return;
4349
CustomerView.drawStamps(widgetAppState.settings.cardSize);
4450
}
4551
};

widget/layouts/layout1.css

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ body {
8080
font-weight: 400;
8181
color: var(--bf-theme-body-text);
8282
}
83+
8384
.mdc-dialog__actions {
8485
padding-top: 24px;
8586
}
@@ -98,15 +99,16 @@ body {
9899
.mdc-text-field__input {
99100
font-size: 16px;
100101
font-weight: 400;
101-
color: var(--bf-theme-body-text) !important;
102102
}
103103

104104
.customer-info #lifeTimeStamps, .customer-info #lifeTimeRedeems {
105105
font-size: 14px;
106106
font-weight: 400;
107107
color: var(--bf-theme-body-text);
108+
}
108109

109-
110+
#userName {
111+
color: var(--bf-theme-body-text);
110112
}
111113

112114
#stampsActionContainer #decrementStamp {
@@ -145,19 +147,27 @@ body {
145147
#stampsAction .add-stamp-title {
146148
color: var(--bf-theme-header-text);
147149
}
150+
#friendlyId {
151+
color: var(--bf-theme-body-text) !important;
152+
}
148153

149154
.available-reward-title {
150155
color: var(--bf-theme-header-text);
151156
}
152157

153158
.mdc-checkbox {
154-
color: var(--bf-theme-primary);
159+
color: var(--bf-theme-primary);
155160
}
156-
.mdc-checkbox__native-control:enabled:checked~.mdc-checkbox__background, .mdc-checkbox__native-control:enabled:indeterminate~.mdc-checkbox__background {
161+
162+
.mdc-checkbox__native-control:enabled:checked ~ .mdc-checkbox__background, .mdc-checkbox__native-control:enabled:indeterminate ~ .mdc-checkbox__background {
157163
border-color: var(--bf-theme-primary);
158164
background-color: var(--bf-theme-primary);
159165
}
160-
.mdc-checkbox .mdc-checkbox__native-control:checked~.mdc-checkbox__background::before {
166+
.mdc-checkbox__native-control:enabled:not(:checked):not(:indeterminate)~.mdc-checkbox__background {
167+
border-color: var(--bf-theme-primary-text);
168+
}
169+
170+
.mdc-checkbox .mdc-checkbox__native-control:checked ~ .mdc-checkbox__background::before {
161171
background-color: var(--bf-theme-primary);
162172
}
163173

widget/style/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ body.has-safe-area #home {
5151
.rewardListContainer .listView-items {
5252
margin-bottom: 14px;
5353
}
54-
.friendlyId {
54+
#friendlyId {
5555
padding-bottom: 1rem;
5656
}
5757

@@ -157,7 +157,7 @@ body.has-safe-area #transactionCustomerList, body.has-safe-area #transactionEmpl
157157

158158
.customer-info #lifeTimeStamps {
159159
margin-top: 8px;
160-
margin-bottom: 12px;
160+
margin-bottom: 2px;
161161
}
162162

163163
.customer-info #lifeTimeStamps, .customer-info #lifeTimeRedeems {

0 commit comments

Comments
 (0)