Skip to content

Commit

Permalink
feature: old codebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
siradji committed Aug 17, 2023
1 parent 8e1f80a commit 2f7fb24
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 34,471 deletions.
17 changes: 10 additions & 7 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"expo": {
"name": "EatLater Vendors",
"description": "Order food from your favorite vendors and restaurants",
"slug": "eatlater-vendors",
"owner": "eatlater",
"version": "0.0.0",
"name": "Nana Vendors",
"description": "Reach a wider audience and sell more with Nana",
"slug": "nana-vendors-app",
"owner": "nana-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/app-config/icon.png",
"scheme": "myapp",
Expand All @@ -27,7 +27,10 @@
"adaptiveIcon": {
"foregroundImage": "./assets/anImageThatDoesNotExist.png",
"backgroundColor": "#FFFFFF"
}
},
"permissions": [
"android.permission.RECORD_AUDIO"
]
},
"updates": {
"fallbackToCacheTimeout": 0
Expand All @@ -43,7 +46,7 @@
},
"extra": {
"eas": {
"projectId": "aef4b4d0-bb0f-4a37-b455-2833d9ae026a"
"projectId": "58e19edd-8d6d-4cbe-9998-c40b1f0fa020"
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions mobile-app/api/_request.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {ApiRoute, APIService, NetworkMapper, PlaygroundServicePort} from "@api/network.mapper";
import axios, { Method} from 'axios'
import {persistence} from "@api/persistence";
import { showToastStandard } from "@components/commons/Toast";
import {cookieParser} from "../../utils/cookieParser";

export function getUrl (gateway: APIService = "VENDOR_GATEWAY"): string {
const environment = process.env.NODE_ENV

let url: string

if (environment === 'development') {
if (environment === '') {
url = `${NetworkMapper.PLAYGROUND}:${PlaygroundServicePort[gateway]}/${ApiRoute[gateway]}/v1`
} else {
url =`${NetworkMapper.PRODUCTION}/${ApiRoute[gateway]}/v1`
}

// return `https://86ed-197-210-70-209.ngrok-free.app/vendor-gateway/v1`
return url
}

Expand All @@ -39,7 +41,7 @@ async function base<T>(param: baseParamProps<T>) {
const source = CancelToken.source();
setTimeout(() => {
source.cancel();
}, 30000);
}, 50000);
return await axios({
method: param.method,
baseURL: config.baseUrl,
Expand All @@ -48,7 +50,7 @@ async function base<T>(param: baseParamProps<T>) {
cancelToken: source.token,
data: param.data,
})
.then(res => {
.then(res => {
return Promise.resolve({
data: res?.data,
cookies: res.headers['set-cookie'] ?? []
Expand All @@ -61,25 +63,23 @@ async function base<T>(param: baseParamProps<T>) {
if (err.response) {
return Promise.reject(err.response?.data);
}
showToastStandard('Something went wrong', 'error')

return Promise.reject(err);
});
})
}


async function request<T> (method: Method, url: string): Promise<{data: any, cookies: string[]}> {
return await base<T>({method, url})
.then(res => {

if ( res.cookies.length > 0) {
persistence.setSecure(cookieParser(res.cookies[0]))
}
}
return Promise.resolve<{data: any, cookies: string[]}>(res)
})
.catch(err => Promise.reject(err));
}


async function requestData<T> ({method, url, data}: baseParamProps<T>): Promise<{data: any, cookies: string[]}> {
return await base<T>({method, url, data})
.then(res => Promise.resolve<{data: any, cookies: string[]}>(res))
Expand Down
8 changes: 8 additions & 0 deletions mobile-app/components/commons/Toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ export const showTost = (toast: ToastType, message: string, type: 'success' | '
placement: "top",
duration: 3000,
})
}

export const showToastStandard = (message: string, type: 'success' | 'error'): void => {
Toast.show({
type: `app_toast_${type}`,
text1: message,
autoHide: true
})
}
2 changes: 1 addition & 1 deletion mobile-app/components/commons/buttons/GenericButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function GenericButton (props: Props): JSX.Element {
return (
<TouchableOpacity
activeOpacity={activeOpacity}
style={[backgroundColor, tailwind('rounded-xl', {
style={[backgroundColor as any, tailwind('rounded-xl', {
'bg-brand-gray-700': props.disabled,
'flex flex-row justify-center w-full items-center bg-brand-gray-700': props.loading
}), style]}
Expand Down
4 changes: 2 additions & 2 deletions mobile-app/components/commons/inputs/ControlledTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {RegisterOptions} from "react-hook-form/dist/types/validator";

export interface ControlledTextInputWithLabelProps extends TextInputProps {
labelStyle?: StyleProp<TextInputProps>
containerStyle?: StyleProp<TextInputProps>
containerStyle?: StyleProp<any>
label: string
labelTestId: string
moreInfo?: string,
Expand Down Expand Up @@ -90,4 +90,4 @@ function FieldErrorText (props: PropsWithChildren<{}>): JSX.Element {
{props.children}
</Text>
)
}
}
2 changes: 1 addition & 1 deletion mobile-app/components/commons/inputs/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function TextArea ( props: TextAreaProps):JSX.Element {
...otherProps
} = props
return (
<View style={[tailwind(), containerStyle]}>
<View style={containerStyle as any}>
<TextInput
keyboardType={keyboardPad}
style={[tailwind('py-3 px-2.5 flex items-center'), style]}
Expand Down
6 changes: 3 additions & 3 deletions mobile-app/components/commons/inputs/TextInputWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const TextInputWithLabel = forwardRef<any, TextInputWithLabelProps>(
const [inputFocus, setInputFocus] = useState<boolean>(false)

return (
<View style={[tailwind('flex flex-col'), containerStyle]}>
<View style={[tailwind('flex flex-col'), containerStyle as any]}>
<View style={tailwind('flex flex-col mb-2.5 w-full ')}>
<Text
testID={labelTestId}
Expand Down Expand Up @@ -86,7 +86,7 @@ export function ModalTextInput (props: ModalTextInputProps): JSX.Element {
const [inputFocus, setInputFocus] = useState<boolean>(false)

return (
<View style={[tailwind('flex flex-col'), containerStyle]}>
<View style={[tailwind('flex flex-col'), containerStyle as any]}>
<View style={tailwind('flex flex-col mb-2.5 w-full ')}>
<Text
testID={labelTestId}
Expand All @@ -102,7 +102,7 @@ export function ModalTextInput (props: ModalTextInputProps): JSX.Element {
)}
</View>
<BottomSheetTextInput
placeholderTextColor={props.placeholderTextColor ?? getColor('brand-gray-800')}
placeholderTextColor={props.placeholderTextColor ?? getColor('brand-gray-800')}
onFocus={() => setInputFocus(true)}
onBlur={() => setInputFocus(false)}
style={[tailwind('rounded-lg bg-brand-blue-200 py-3.5 px-3 font-medium text-lg text-brand-black-500', {
Expand Down
4 changes: 3 additions & 1 deletion mobile-app/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
const { defineConfig } = require("cypress");

module.exports = defineConfig({
Expand All @@ -17,7 +18,8 @@ module.exports = defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require("./cypress/plugins/index.js")(on, config);
// eslint-disable-next-line global-require
return require("./cypress/plugins/index")(on, config);
},
baseUrl: "http://localhost:19006",
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
Expand Down
62 changes: 62 additions & 0 deletions mobile-app/hooks/useStateWithCallback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {useState, useRef, useEffect} from 'react';

function useStateWithCallback<T> (initialState: T, callback: any): any {
const [state, setState] = useState<T>(initialState);

const didMount = useRef(false);

useEffect(() => {
if (didMount.current) {
callback(state);
} else {
didMount.current = true;
}
}, [state, callback]);

return [state, setState];
};

// const useStateWithCallbackInstant = (initialState, callback) => {
// const [state, setState] = useState(initialState);

// const didMount = React.useRef(false);

// React.useLayoutEffect(() => {
// if (didMount.current) {
// callback(state);
// } else {
// didMount.current = true;
// }
// }, [state, callback]);

// return [state, setState];
// };

// const useStateWithCallbackLazy = initialValue => {
// const callbackRef = React.useRef(null);

// const [value, setValue] = React.useState(initialValue);

// React.useEffect(() => {
// if (callbackRef.current) {
// callbackRef.current(value);

// callbackRef.current = null;
// }
// }, [value]);

// const setValueWithCallback = React.useCallback(
// (newValue, callback) => {
// callbackRef.current = callback;

// return setValue(newValue);
// },
// [],
// );

// return [value, setValueWithCallback];
// };

// export { useStateWithCallbackInstant, useStateWithCallbackLazy };

export default useStateWithCallback;
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function SingleMenu ({route, navigation}: SingleMenuNavProps): JSX.Elemen
})

const [image, setImage] = useState<string>('')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [ _option , setOptions] = useState<ListingOptionGroupI[]>([])
const [hasEdit, setHasEdit] = useState<boolean>(false)
// state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export function OrderCategory (props: PropsWithChildren<OrderCatergoryProps>): J
const onPress = (order: OrderI): void => navigation.navigate("GetOrder", {order})

return (

<ScrollView style={[tailwind('px-3 h-full'),{

}]}>
{props.orders.length === 0 && (
<EmptyAnimation text='No orders yet.' />
)}

{props.orders.length > 0 && props.orders.map((order, index) => {
{props.orders.length > 0 && props.orders.map((order) => {
switch (props.type) {
case OrderStatus.PROCESSED:
case OrderStatus.COLLECTED:
Expand All @@ -43,7 +43,7 @@ export function OrderCategory (props: PropsWithChildren<OrderCatergoryProps>): J
return (
<OrdersCard order={order} key={order.refId} onPress={onPress}/>
)
case OrderStatus.FULFILLED:
case OrderStatus.FULFILLED:
return (
<DeliveredOrderCard order={order} onPress={onPress} key={order.refId} />
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function OrderSection (props:PropsWithChildren<{width?: StyleProp<ViewPro
return (
<View style={[tailwind('flex flex-col', {
'w-full': fullWidth
}), props.width]}>
}), props.width as any]}>
<Text style={tailwind('font-semibold text-xl text-brand-black-500 mb-2.5')}>{heading}</Text>
{children}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function OrdersScreen (): JSX.Element {
const {profile, hasFetchedProfile} = useAppSelector((state: RootState) => state.profile )
const layout = useWindowDimensions();
const [index, setIndex] = useState<number>(0);
const [routes, _setRoutes] = useState<Array<{key: string, title: string}>>(DATA);
const [routes] = useState<Array<{key: string, title: string}>>(DATA);
const [showProfileCompleteMsg, setShowProfileCompleteMsg] = useState<boolean>(false)
const bottomSheetModalRef = useRef<any>(null)

Expand Down Expand Up @@ -76,14 +76,14 @@ export function OrdersScreen (): JSX.Element {
}, [hasFetchedOrders, orders])

const renderScene = SceneMap<any>({

delivered: () => <OrderCategory
orders={getFulfilledOrders()}
testId='OrdersScreen.OrderCategory.PENDING'
type={OrderStatus.FULFILLED}
/>,
route: () => <OrderCategory
orders={ordersInTransit()}
type={OrderStatus.COLLECTED}
type={OrderStatus.IN_ROUTE}
/>,
pre: () => <OrderCategory
orders={getPreOrders()}
Expand Down Expand Up @@ -140,9 +140,9 @@ export function OrdersScreen (): JSX.Element {
function checkProfileCompleteStatus (): void {
if (!hasFetchedProfile ) {
setShowProfileCompleteMsg(false)
return
return
}

if (profile.settings?.operations === undefined) {
setShowProfileCompleteMsg(true)
}
Expand All @@ -162,7 +162,7 @@ export function OrdersScreen (): JSX.Element {
style={tailwind('w-full bg-brand-gray-500 h-full flex-col flex pb-5')}
>
<View testID="OrdersScreen" style={tailwind('px-3.5 py-5')}>
{hasFetchedProfile && (<OrderHeaderStatus status={profile.status as any} />)}
<OrderHeaderStatus status={profile.status as any} />
{showProfileCompleteMsg && (<CompleteProfileMsg />)}
<OrdersStats
hasFetchedOrders={hasFetchedOrders}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {useSafeAreaInsets} from "react-native-safe-area-context";
import {PaymentSettings} from "@screens/AppNavigator/SettingsNavigator/screens/PaymentSetting";
import {RestaurantSettings} from "@screens/AppNavigator/SettingsNavigator/screens/RestaurantSettings";


export interface SettingsParamsList {
AccountProfile: undefined,
RestaurantProfile: | undefined,
Expand Down
Loading

0 comments on commit 2f7fb24

Please sign in to comment.