Skip to content

Commit

Permalink
fix: remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-lipski committed Aug 30, 2024
1 parent 3f12c05 commit 83524e1
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
5 changes: 3 additions & 2 deletions native/db/hooks/useGetInventoryName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const getInventoryName = async (inventoryId: number) => {
return res.data?.name ?? "";
};

export const useGetInventoryName = (inventoryId: number) =>
export const useGetInventoryName = (inventoryId?: number) =>
useQuery({
queryKey: ["inventoryName", inventoryId],
queryFn: async () => await getInventoryName(inventoryId),
queryFn: async () => await getInventoryName(inventoryId!),
enabled: !!inventoryId,
});
8 changes: 5 additions & 3 deletions native/db/hooks/useListProductRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const listRecords = async (inventoryId: number) => {
if (error) throw new Error(error.message);
return data;
};
export const useListProductRecords = (inventoryId: number) => {
const query = useQuery(["recordsList", inventoryId], () =>
listRecords(inventoryId)
export const useListProductRecords = (stockId?: number) => {
const query = useQuery(
["recordsList", stockId],
() => listRecords(stockId!),
{ enabled: !!stockId }
);
return query;
};
7 changes: 4 additions & 3 deletions native/db/hooks/useListRecipeRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ const listRecipeRecords = async (inventoryId: number) => {
if (error) throw new Error(error.message);
return data;
};
export const useListRecipeRecords = (inventoryId: number) => {
export const useListRecipeRecords = (stockId?: number) => {
const queryClient = useQueryClient();
const query = useQuery({
queryKey: ["recipeRecordsList", inventoryId],
queryFn: () => listRecipeRecords(inventoryId),
queryKey: ["recipeRecordsList", stockId],
queryFn: () => listRecipeRecords(stockId!),
onSuccess: () =>
queryClient.invalidateQueries({
queryKey: ["recipeRecord"],
}),
enabled: !!stockId,
});
return query;
};
6 changes: 4 additions & 2 deletions native/db/hooks/useListRecipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const useListRecipes = () => {
return useQuery(["recipeList"], () => listAllRecipes());
};

export const useListRecipesWithRecords = (stockId: number) => {
return useQuery(["recipeList", stockId], () => listRecipesOfStock(stockId));
export const useListRecipesWithRecords = (stockId?: number) => {
return useQuery(["recipeList", stockId], () => listRecipesOfStock(stockId!), {
enabled: !!stockId,
});
};
5 changes: 4 additions & 1 deletion native/maestro/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
### Prerequisites for running e2e tests


Install the `maestro` e2e tool on your system.
Clean the db with `npm run reset-db` in project root.

For Android, have the Android Studio set up and start the app in an emulator in `./native` with `ANDROID_HOME=PATH_TO_ANDROID_SDK npm run expo -- start -a`.

Of course, if testing edge functions, start them too.
Of course, if testing edge functions, start them too. Remember to run then in test mode to avoid api calls.

### Running the tests

Run with `maestro test flow_name.yaml`

The interactive `maestro studio` can be very helpful.
3 changes: 0 additions & 3 deletions native/screens/DocumentScannerModalScreen/DocumentScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const DocumentScanner = ({
isPreviewShown: !s.isPreviewShown,
isTakingPhoto: false,
}));
// dispatch(documentScannerAction.PHOTO_TAKE({ photo }));
// dispatch(documentScannerAction.SWITCH_PREVIEW());
// dispatch(documentScannerAction.PHOTO_END());
return;
};

Expand Down
1 change: 0 additions & 1 deletion native/screens/DocumentScannerModalScreen/PhotoPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const PhotoPreview = ({
photo: null,
isPreviewShown: false,
}))
// () => dispatch(documentScannerAction.PHOTO_RETAKE())
}
size="s"
type="primary"
Expand Down
8 changes: 8 additions & 0 deletions native/screens/ListTabScreen/ListTabScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const groupByDay = (data: ReturnType<typeof useListInventories>["data"]) => {
if (!data) return null;
const days: { [key: string]: typeof data } = {};
data.forEach((item) => {
if (!item || !item.date) return;
const day = new Date(item.date).toLocaleString("pl-PL", {
day: "numeric",
month: "numeric",
Expand Down Expand Up @@ -121,6 +122,13 @@ export const ListTab = ({ navigation }: ListTabScreenProps) => {
);
}

console.log(
months.map(([mn, days]) =>
days.map(([dn, invs]) =>
invs.map((i) => mn + " " + dn + " " + (i?.id?.toString() || "und"))
)
)
);
return (
<SafeAreaView edges={["left", "right"]} style={styles.screen}>
<ScrollView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const initialProductRecords: ProductRecordsByProductId = {};
const initialRecipeRecords: RecipeRecordsByRecipeId = {};

type StockContextType = StockData & {
stockId: number;
setStockId: React.Dispatch<React.SetStateAction<number>>;
stockId?: number;
setStockId: React.Dispatch<React.SetStateAction<number | undefined>>;
// stockType: "inventory" | "delivery";
setProductRecords: React.Dispatch<
React.SetStateAction<ProductRecordsByProductId>
Expand Down Expand Up @@ -66,7 +66,7 @@ export const StockContextProvider = ({
stockId: number | undefined;
}) => {
const { data: stocks } = useListInventories();
const latestStockId = stocks?.[0]?.id || -1;
const latestStockId = stocks?.[0]?.id;

const [stockId, setStockId] = useState(routeStockId ?? latestStockId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export const mergeRawAndScannedRecords = (
}

// Adjust merged product records according to scanned recipe records
//
// WIP: Differentiate the behaviour based on wether in delivery or inventory mode.
// (subtract product records when in inventory mode)
const recipeParts = recipeList?.find(
(r) => r.id.toString() === recipe_id
)?.recipe_part;
Expand Down
2 changes: 1 addition & 1 deletion native/screens/StockTabScreen/StockTabScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function StockTabScreen({
// const { showError, showInfo, showSuccess } = useSnackbar();
const { showError, showSuccess } = useSnackbar();

const { data: inventoryName } = useGetInventoryName(+stockId);
const { data: inventoryName } = useGetInventoryName(stockId);

const {
productRecords,
Expand Down

0 comments on commit 83524e1

Please sign in to comment.