Skip to content

Commit

Permalink
Merge pull request #14 from eatlaterhq/siradji/feature/orders
Browse files Browse the repository at this point in the history
Siradji/feature/orders
  • Loading branch information
siradji authored Mar 12, 2023
2 parents a914f2a + 1757520 commit 8e1f80a
Show file tree
Hide file tree
Showing 63 changed files with 22,105 additions and 30,951 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
cypress/
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@
"@typescript-eslint/default-param-last": "off",
"no-plusplus": "off",
"radix": "off",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-unused-expressions": "off",
"react/no-unescaped-entities": "off",
"no-void": "off",
"no-restricted-globals": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}],
"no-nested-ternary": "off",
"no-await-in-loop": "off",
"import/no-extraneous-dependencies": "off",
Expand Down
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/anImageThatDoesNotExist.png",
"backgroundColor": "#FFFFFF"
}
},
"updates": {
"fallbackToCacheTimeout": 0
},
Expand Down
1 change: 1 addition & 0 deletions mobile-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ConnectionBoundary from '@components/commons/ConnectionBoundary';
import { AppToast } from '@components/commons/AppToast';
import { ToastProps } from "react-native-toast-notifications/lib/typescript/toast";
import { ToastProvider } from "react-native-toast-notifications"

export default function App() {
const isLoaded = useCachedResource()
const logger = useLogger()
Expand Down
19 changes: 12 additions & 7 deletions mobile-app/api/_request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ApiRoute, APIService, NetworkMapper, PlaygroundServicePort} from "@api/network.mapper";
import axios, {AxiosError, Method} from 'axios'
import axios, { Method} from 'axios'
import {persistence} from "@api/persistence";
import {cookieParser} from "../../utils/cookieParser";

Expand All @@ -8,7 +8,7 @@ export function getUrl (gateway: APIService = "VENDOR_GATEWAY"): string {

let url: string

if (environment === '') {
if (environment === 'development') {
url = `${NetworkMapper.PLAYGROUND}:${PlaygroundServicePort[gateway]}/${ApiRoute[gateway]}/v1`
} else {
url =`${NetworkMapper.PRODUCTION}/${ApiRoute[gateway]}/v1`
Expand Down Expand Up @@ -44,7 +44,7 @@ async function base<T>(param: baseParamProps<T>) {
method: param.method,
baseURL: config.baseUrl,
url: param.url,
headers: param.headers ?? config.headers,
headers: param.headers !== undefined ? param.headers : config.headers,
cancelToken: source.token,
data: param.data,
})
Expand All @@ -55,22 +55,27 @@ async function base<T>(param: baseParamProps<T>) {
});
})
.catch((err: any) => {
console.log(JSON.stringify(err))
if (err.message.includes('401')) {
return Promise.reject(err.response?.data);
}
if (err.response) {
return Promise.reject(err.response?.data);
}
return Promise.reject('TIMEOUT');

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 => {
res.cookies.length > 0 && persistence.setSecure(cookieParser(res.cookies[0]))

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

.catch(err => Promise.reject(err));
}

Expand Down
1 change: 0 additions & 1 deletion mobile-app/components/Text/TextWithMoreInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {tailwind} from '@tailwind'
interface TextWithMoreInfoProps {
moreInfo: string
moreInfoStyle?: StyleProp<TextStyle>
textStyle?: StyleProp<TextStyle>
containerStyle?: StyleProp<ViewStyle>
text: string
}
Expand Down
1 change: 1 addition & 0 deletions mobile-app/components/commons/AppToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tailwind } from '@tailwind';
import {View, Text} from 'react-native'
import { ToastProps } from "react-native-toast-notifications/lib/typescript/toast";
import { IconComponent } from './IconComponent';

interface AppToastProps {
toast: ToastProps;
type: "success" | "error"
Expand Down
2 changes: 1 addition & 1 deletion mobile-app/components/commons/CompleteProfileMsg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function CompleteProfileMsg (): JSX.Element {
<View style={tailwind('flex flex-col w-full rounded-lg py-4 px-3 bg-warning-200')}>
<View style={tailwind('flex w-full flex-row items-center')}>
<IconComponent iconType='Feather' name='alert-triangle' />
<Text style={tailwind('text-xs text-brand-black-500 font-medium ml-2')}>Your listings are not visible. Complete your vendor's profile to start selling on EatLater.</Text>
<Text style={tailwind('text-xs text-brand-black-500 ml-1')}>Complete your vendor's profile to start selling on EatLater.</Text>
</View>
</View>
)
Expand Down
3 changes: 1 addition & 2 deletions mobile-app/components/commons/ConnectionBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useNetInfo, fetch } from "@react-native-community/netinfo";
import { View, Image, Text } from "react-native";
import ImageConnectionProblem from "@assets/images/misc/connection_problem.png";
import { View } from "react-native";
import { tailwind } from "@tailwind";
import Lottie from 'lottie-react-native'
import Animation from '@assets/app/12701-no-internet-connection.json'
Expand Down
11 changes: 11 additions & 0 deletions mobile-app/components/commons/Toast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import Toast from "react-native-toast-message";
import { ToastType } from "react-native-toast-notifications";

export const ShowToast = (type: 'success' | 'error', message: string) => {
Toast.show({
type: type,
text1: message,
autoHide: true
});
}

export const showTost = (toast: ToastType, message: string, type: 'success' | 'error' ): void =>{
toast.hideAll()
toast.show(message, {
type: `app_toast_${type}`,
placement: "top",
duration: 3000,
})
}
3 changes: 2 additions & 1 deletion mobile-app/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
const { defineConfig } = require("cypress");

module.exports = defineConfig({
Expand All @@ -16,7 +17,7 @@ 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.ts")(on, config);
return require("./cypress/plugins/index.js")(on, config);
},
baseUrl: "http://localhost:19006",
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
Expand Down
2 changes: 1 addition & 1 deletion mobile-app/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["**/*.ts"],
"include": ["**/*.ts", "plugins/index.ts"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
Expand Down
3 changes: 2 additions & 1 deletion mobile-app/screens/AppNavigator/AppNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Linking from "expo-linking"
import {useEffect} from "react";
import {fetchProfile} from "@store/profile.reducer";
import {fetchOrders} from "@store/orders.reducer";
import Toast from 'react-native-toast-message'
import { useAppDispatch} from "@store/index";
import {fetchAllListings} from "@store/listings.reducer";
import { fetchWallet } from "@store/wallet.reducer";

const App = createStackNavigator<AppParamList>()

Expand All @@ -22,6 +22,7 @@ export function AppNavigator(): JSX.Element {
dispatch(fetchProfile() as any)
dispatch(fetchOrders() as any)
dispatch(fetchAllListings())
dispatch(fetchWallet())
}, [])


Expand Down
28 changes: 22 additions & 6 deletions mobile-app/screens/AppNavigator/BottomNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {SettingsNavigator} from "@screens/AppNavigator/SettingsNavigator/Setting
import {WalletNavigator} from "@screens/AppNavigator/WalletNavigator/WalletNavigator";
import {ReviewNavigator} from "@screens/AppNavigator/ReviewNavigator/ReviewNavigator";
import { RootState, useAppSelector } from '@store/index';
import { useEffect, useState } from 'react';

const BottomTab = createBottomTabNavigator<BottomTabParamList>()

Expand All @@ -35,7 +36,22 @@ const getTabBarLabel = (props: {
);

export function BottomTabNavigator ():JSX.Element {
const {profile} = useAppSelector((state: RootState) => state.profile)
const {profile, hasFetchedProfile} = useAppSelector((state: RootState) => state.profile)
const [profileComplete, setProfileComplete] = useState<boolean>(true)

useEffect(() => {
if (profile.settings?.operations === undefined) {
setProfileComplete(false)
return
}
if (profile.settings?.payment === undefined) {
setProfileComplete(false)
return
}

setProfileComplete(true)

}, [hasFetchedProfile])
return (
<BottomTab.Navigator
initialRouteName={AppScreenName.ORDERS}
Expand All @@ -44,8 +60,8 @@ export function BottomTabNavigator ():JSX.Element {
tabBarLabelPosition: "below-icon",
tabBarStyle: tailwind(
"px-5 py-2 h-24 border-t-0.5 border-brand-black-500 "),
tabBarActiveTintColor: getColor("primary-500"),
tabBarInactiveTintColor: getColor("brand-black-500"),
tabBarActiveTintColor: getColor("primary-800"),
tabBarInactiveTintColor: getColor("brand-gray-400"),
tabBarItemStyle: tailwind({ "pb-6 pt-2": Device.osName === 'iOS'}),
}}
>
Expand Down Expand Up @@ -116,13 +132,13 @@ export function BottomTabNavigator ():JSX.Element {
getTabBarLabel({
focused,
color,
title: 'Settings',
title: 'Profile',
}),
tabBarTestID: "BottomTabHome",
tabBarIcon: ({ color }) => (
<View style={tailwind('relative')}>
<IconComponent style={tailwind()} iconType='Feather' name="settings" size={24} color={color}/>
{profile.settings?.operations === undefined || profile.settings?.payment === undefined && (<View style={tailwind('absolute z-50 w-2 h-2 rounded-full bg-red-500 top-0 right-0 ')} />)}
<IconComponent style={tailwind()} iconType='MaterialCommunityIcons' name="account-circle-outline" size={24} color={color}/>
{!profileComplete && (<View style={tailwind('absolute z-50 w-2 h-2 rounded-full bg-red-500 top-0 right-0 ')} />)}
</View>
),
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Dimensions, Pressable, ScrollView, Switch, Text, View} from "react-native";
import { Pressable, ScrollView, Switch, Text, View} from "react-native";
import {getColor, tailwind} from '@tailwind'
import {useEffect, useState} from "react";
import {StackScreenProps} from "@react-navigation/stack";
Expand All @@ -9,13 +9,14 @@ import {GenericButton} from "@components/commons/buttons/GenericButton";
import {IconComponent} from "@components/commons/IconComponent";
import {TextWithMoreInfo} from "@components/Text/TextWithMoreInfo";
import {useForm} from "react-hook-form";
import {CreateListingCategoryDto} from "@imagyne/eatlater-types/dist/dto/listing.dto";
import {ControlledTextInputWithLabel} from "@components/commons/inputs/ControlledTextInput";
import { ListingMenuI} from "@imagyne/eatlater-types";
import {IconButton} from "@components/commons/buttons/IconButton";
import {useAppDispatch} from "@store/index";
import {addOrUpdateCategory, fetchCategories, updateOptionGroup} from "@store/listings.reducer";
import {addOrUpdateCategory} from "@store/listings.reducer";
import Toast from "react-native-toast-message";
import { showTost } from "@components/commons/Toast";
import { useToast } from "react-native-toast-notifications";

type AddCategoryNavProps = StackScreenProps<ListingsParams, "AddCategory">
enum TagSelection {
Expand All @@ -38,7 +39,9 @@ export function AddCategory ({route, navigation}: AddCategoryNavProps): JSX.Elem
const [isLive, setIsLive] = useState<boolean>(false)
const [tags, setTags] = useState<string[]>([])
const dispatch = useAppDispatch()
const {control, setValue, handleSubmit, getValues} = useForm<CreateListingCategoryDto>()
const toast = useToast()

const {control, setValue, handleSubmit, getValues} = useForm<any>()

const [menu, setMenu] = useState<ListingMenuI[]>([])
const [loading, setIsLoading] = useState<boolean>(false)
Expand All @@ -63,8 +66,7 @@ export function AddCategory ({route, navigation}: AddCategoryNavProps): JSX.Elem
setTags((prevState) => [...prevState, tag])
break;
case TagSelection.UNSELECT:
const newTags = tags.filter(_tag => tag !== _tag)
setTags(newTags)
setTags(tags.filter(_tag => tag !== _tag))
break;
}

Expand All @@ -74,7 +76,7 @@ export function AddCategory ({route, navigation}: AddCategoryNavProps): JSX.Elem
setMenu((prev) => prev.filter(m => m._id !== menu._id))
}

async function onSubmit (data: CreateListingCategoryDto) {
async function onSubmit (data: any) {
let type: string = 'CREATE'
let payload;
if (route?.params?.category !== undefined) {
Expand Down Expand Up @@ -106,16 +108,13 @@ export function AddCategory ({route, navigation}: AddCategoryNavProps): JSX.Elem
autoHide: true,
})

showTost(toast, 'Category added!', 'success')
setTimeout(() => {
void navigation.goBack()
}, 3000)
}
} catch (error: any) {
// Toast.show({
// type: 'error',
// text1: typeof error.message !== 'string' ? error.message[0] : error.message,
// autoHide: true,
// })
showTost(toast, typeof error.message !== 'string' ? error.message[0] : error.message, 'error')
} finally {
setIsLoading(false)
}
Expand Down
Loading

0 comments on commit 8e1f80a

Please sign in to comment.