-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
295 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,62 @@ | ||
import React from 'react'; | ||
|
||
import { Slot } from 'expo-router'; | ||
import { useObservableEagerState, ObservableResource } from 'observable-hooks'; | ||
import { map, distinctUntilChanged } from 'rxjs/operators'; | ||
|
||
import { Suspense } from '@wcpos/components/suspense'; | ||
import { useAppState } from '@wcpos/core/contexts/app-state'; | ||
import { useCollection } from '@wcpos/core/screens/main/hooks/use-collection'; | ||
import { CurrentOrderProvider } from '@wcpos/core/screens/main/pos/contexts/current-order'; | ||
import type { OrderDocument } from '@wcpos/database'; | ||
|
||
export default function POSLayout() { | ||
// Set up the auth context and render our layout inside of it. | ||
return <Slot />; | ||
const { wpCredentials, store } = useAppState(); | ||
const cashierID = useObservableEagerState(wpCredentials.id$); | ||
const storeID = useObservableEagerState(store.id$); | ||
const { collection: ordersCollection } = useCollection('orders'); | ||
|
||
/** | ||
* We then need to filter the open orders to limit by cashier and store | ||
* | ||
* @TODO - it would be nice to be able to query ($elemMatch) by cashier and store, but | ||
* there are too many edge cases, ie: cashier is not set, store is not set, etc. | ||
* For now, we'll just filter the results. | ||
*/ | ||
const resource = React.useMemo( | ||
() => | ||
new ObservableResource( | ||
ordersCollection.find({ selector: { status: 'pos-open' } }).$.pipe( | ||
map((docs: OrderDocument[]) => { | ||
const filteredDocs = docs.filter((doc) => { | ||
const metaData = doc.meta_data; | ||
const _pos_user = metaData.find((item) => item.key === '_pos_user')?.value; | ||
const _pos_store = metaData.find((item) => item.key === '_pos_store')?.value; | ||
if (storeID === 0) { | ||
return _pos_user === String(cashierID); | ||
} | ||
return _pos_user === String(cashierID) && _pos_store === String(storeID); | ||
}); | ||
const filteredAndSortedDocs = filteredDocs.sort((a, b) => | ||
a.date_created_gmt.localeCompare(b.date_created_gmt) | ||
); | ||
return filteredAndSortedDocs.map((doc) => ({ id: doc.uuid, document: doc })); | ||
}), | ||
distinctUntilChanged((prev, next) => prev.length === next.length) | ||
) | ||
), | ||
[cashierID, ordersCollection, storeID] | ||
); | ||
|
||
return ( | ||
<Suspense> | ||
<CurrentOrderProvider | ||
resource={resource} //</Suspense>currentOrderUUID={route.params?.orderID} | ||
> | ||
<Suspense> | ||
<Slot /> | ||
</Suspense> | ||
</CurrentOrderProvider> | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1 @@ | ||
import { Text, View } from 'react-native'; | ||
|
||
import { Link } from 'expo-router'; | ||
|
||
import { useAppState } from '@wcpos/core/contexts/app-state'; | ||
|
||
export default function Index() { | ||
const { logout } = useAppState(); | ||
|
||
return ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
<Text>Home Screen</Text> | ||
<Link href="/(app)/(modal)/settings">Present modal</Link> | ||
|
||
<Text | ||
onPress={() => { | ||
// The `app/(app)/_layout.tsx` will redirect to the sign-in screen. | ||
logout(); | ||
}} | ||
> | ||
Sign Out | ||
</Text> | ||
</View> | ||
); | ||
} | ||
export { POS as default } from '@wcpos/core/screens/main/pos/pos'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
import { View } from 'react-native'; | ||
|
||
import { Text } from '@wcpos/components/text'; | ||
|
||
export default function Login() { | ||
return ( | ||
<View> | ||
<Text>Login</Text> | ||
</View> | ||
); | ||
} | ||
export { Login as default } from '@wcpos/core/screens/auth/login'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.