Skip to content

Commit

Permalink
Merge pull request #7 from niloo-fs/niloofar/75914/convert-shared-uti…
Browse files Browse the repository at this point in the history
…ls-to-TS

Niloofar Sadeghi / Convert hooks, loader, loader-handler, location to TS [shared-utiles]
  • Loading branch information
jim-deriv authored Sep 23, 2022
2 parents 6e01d99 + ce7725f commit 262a7ad
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 21 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export const useNewRowTransition = is_new_row => {
export const useNewRowTransition = (is_new_row: boolean) => {
const [in_prop, setInProp] = React.useState(!is_new_row);

React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const moduleLoader = (lazyComponent, attempts = 2, interval = 1500) => {
export const moduleLoader = (lazyComponent: () => Promise<unknown>, attempts = 2, interval = 1500) => {
return new Promise((resolve, reject) => {
lazyComponent()
.then(resolve)
.catch(error => {
.catch((error: unknown) => {
// let us retry after 1500 ms
setTimeout(() => {
if (attempts === 1) {
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions packages/shared/src/utils/loader/lazy-load.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/shared/src/utils/loader/lazy-load.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import Loadable from 'react-loadable';

export const makeLazyLoader =
(importFn: () => Promise<unknown>, loaderFn: () => JSX.Element) => (component_name?: string) =>
Loadable.Map({
loader: {
ComponentModule: importFn,
},
render(loaded: { [key: string]: any }, props: object) {
const ComponentLazy = component_name
? loaded.ComponentModule.default[component_name]
: loaded.ComponentModule.default;
return <ComponentLazy {...props} />;
},
loading: loaderFn,
});
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
export const getLocation = (location_list, value, type) => {
type TType = {
text: string;
value: string;
};

type TLocationList = TType & {
identity: {
services: {
idv: object;
onfido: object;
};
};
phone_idd: string;
};

export const getLocation = (location_list: TLocationList[], value: string, type: keyof TType) => {
const location_obj = location_list.find(
location => location[type === 'text' ? 'value' : 'text'].toLowerCase() === value.toLowerCase()
);
Expand Down Expand Up @@ -41,4 +56,4 @@ const eu_countries = [
'mt',
];
// check if client is from EU
export const isEuCountry = country => eu_countries.includes(country);
export const isEuCountry = (country: string) => eu_countries.includes(country);

0 comments on commit 262a7ad

Please sign in to comment.