Skip to content

Commit

Permalink
Merge pull request #807 from Autofleet/AUT-18615-switch-demand-source
Browse files Browse the repository at this point in the history
Aut 18615 switch demand source
  • Loading branch information
ormiz authored Feb 12, 2024
2 parents 1ebe6b5 + 4ff5bcf commit 1587e54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion examples/client/Locomotion/src/context/user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,32 @@ const UserContextProvider = ({ children }: { children: any }) => {
return vertResponse.status === 'OK';
};

const getAllowedDemandSourceIds = (): string[] => {
try {
if (!Config.ALLOWED_DEMAND_SOURCE_IDS) {
return [];
}
const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS);
return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : [];
} catch (error) {
Mixpanel.setEvent('Invalid ALLOWED_DEMAND_SOURCE_IDS', { allowedDemandSourceIds: Config.ALLOWED_DEMAND_SOURCE_IDS });
return [];
}
};

const onLogin = async (phoneNumber: string, channel = 'sms') => {
const demandSourceId = await AppSettings.getOperationId();
await loginApi({
const allowedDemandSourceIds = getAllowedDemandSourceIds();
const response = await loginApi({
phoneNumber,
channel,
demandSourceId,
allowedDemandSourceIds,
});
const { selectedDemandSourceId } = response;
if (allowedDemandSourceIds.length > 0 && selectedDemandSourceId && selectedDemandSourceId !== demandSourceId) {
await AppSettings.setOperationId(selectedDemandSourceId);
}
// successful login - delete captcha token
await StorageService.delete('captchaToken');
};
Expand Down
1 change: 1 addition & 0 deletions examples/client/Locomotion/src/services/app-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const AppSettings = {
},
});
},
setOperationId: async newOperationId => AppSettings.setSettings({ operationId: newOperationId }),
destroy: async () => Storage.clear(),
};

Expand Down

0 comments on commit 1587e54

Please sign in to comment.