Skip to content

Commit

Permalink
fix: can add stock when none exist
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-lipski committed Aug 27, 2024
1 parent 7cbba45 commit e627fdb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
23 changes: 6 additions & 17 deletions native/screens/NewStockScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function NewStockScreen({ navigation }: NewStockScreenProps) {
});
const {
mutate,
data: inventory,
data: stock,
isSuccess,
isLoading,
isError,
Expand All @@ -59,24 +59,13 @@ export function NewStockScreen({ navigation }: NewStockScreenProps) {
const is_delivery = watch("is_delivery");

useEffect(() => {
if (isSuccess && inventory) {
if (is_delivery) {
navigation.navigate("Tabs", {
screen: "StockTab",
params: {
id: inventory.id,
},
});
return;
}
navigation.navigate("Tabs", {
screen: "StockTab",
params: {
id: inventory.id,
},
if (isSuccess && stock && !!stock.id) {
navigation.navigate("StockTabScreen" as any, {
id: stock.id,
stockType: is_delivery ? "delivery" : "inventory",
});
}
}, [navigation, isSuccess, inventory, is_delivery]);
}, [navigation, isSuccess, stock]);

useEffect(() => {
if (isError) {
Expand Down
42 changes: 25 additions & 17 deletions native/screens/StockTabScreen/StockTabScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function StockTabScreen({
const styles = useStockTabStyles();

const { isConnected } = useNetInfo();
const inventoryId = route.params?.id;
const stockId = route.params?.id;
const stockType = route.params?.stockType;

const { recordsFromInvoice, recordsFromSalesRaport, aliasForm } =
Expand All @@ -38,7 +38,7 @@ export default function StockTabScreen({
// const { showError, showInfo, showSuccess } = useSnackbar();
const { showError, showSuccess } = useSnackbar();

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

const {
productRecords,
Expand All @@ -58,8 +58,8 @@ export default function StockTabScreen({
}, [recordsFromSalesRaport]);

useEffect(() => {
setStockId(inventoryId);
}, [inventoryId]);
setStockId(stockId);
}, [stockId]);

const {
productsIsSuccess,
Expand All @@ -69,19 +69,19 @@ export default function StockTabScreen({
} = useProductRecords();

const { data: recipeList, isSuccess: recipesIsSuccess } =
useListRecipesWithRecords(inventoryId);
useListRecipesWithRecords(stockId);

const {
mutate,
isSuccess: isUpdateSuccess,
isError: isUpdateError,
} = useUpdateRecords(+inventoryId);
} = useUpdateRecords(+stockId);
const { mutate: createProductNameAliases } = useCreateProductNameAlias();
const { mutate: createRecipeNameAliases } = useCreateRecipeNameAlias();

useEffect(() => {
navigation.setOptions({ headerTitle: inventoryName });
}, [inventoryId, inventoryName, navigation]);
}, [stockId, inventoryName, navigation]);

useEffect(() => {
if (isUpdateSuccess) {
Expand All @@ -94,10 +94,18 @@ export default function StockTabScreen({
}
}, [isUpdateSuccess, isUpdateError]);

console.log({
p: route.params,
// stockId,
// productsIsSuccess,
// categorizedIsSuccess,
// recipesIsSuccess,
});

if (
!productsIsSuccess ||
!categorizedIsSuccess ||
!inventoryId ||
!stockId ||
!recipesIsSuccess
)
return (
Expand Down Expand Up @@ -127,7 +135,7 @@ export default function StockTabScreen({
onPress={() => {
// necessary hack, handled by parent navigator - be cautious
navigation.navigate("DocumentScannerModal" as any, {
stockId: inventoryId,
stockId: stockId,
stockType,
});
}}
Expand Down Expand Up @@ -159,16 +167,16 @@ export default function StockTabScreen({
onPress={() => {
// necessary hack, handled by parent navigator - be cautious
navigation.navigate("BarcodeModal" as any, {
inventoryId,
inventoryId: stockId,
navigateTo: "StockTab",
});
}}
>
<ScanBarcodeIcon size={34} color="lightGrey" />
</Button>
</View>
<IDListCardAddProduct inventoryId={inventoryId} />
<IDListCardAddRecord inventoryId={inventoryId} />
<IDListCardAddProduct inventoryId={stockId} />
<IDListCardAddRecord inventoryId={stockId} />
{/* <Button type="primary" size="l" fullWidth>
{recordsFromInvoice
? Object.keys(recordsFromInvoice).toString()
Expand All @@ -177,7 +185,7 @@ export default function StockTabScreen({
{recipeList?.map((recipe) => (
<RecipeCard
key={recipe?.id}
inventoryId={inventoryId}
inventoryId={stockId}
name={recipe.name}
recipePart={recipe.recipe_part}
recipeId={recipe.id}
Expand All @@ -190,8 +198,8 @@ export default function StockTabScreen({
key={product.id}
recordId={product.record_id!}
productId={product.id!}
inventoryId={inventoryId}
id={+inventoryId}
inventoryId={stockId}
id={+stockId}
quantity={product.quantity}
unit={product.unit!}
name={product.name}
Expand All @@ -211,8 +219,8 @@ export default function StockTabScreen({
key={product.id}
recordId={product.record_id!}
productId={product.id!}
inventoryId={inventoryId}
id={+inventoryId}
inventoryId={stockId}
id={+stockId}
quantity={product.quantity}
unit={product.unit!}
name={product.name}
Expand Down

0 comments on commit e627fdb

Please sign in to comment.