Skip to content

Commit

Permalink
fix(ui): replace undefined in URL with default inventory ID
Browse files Browse the repository at this point in the history
  • Loading branch information
lemilonkh committed Jun 27, 2024
1 parent 3148530 commit 9ee18ee
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/src/app/[lng]/[inventory]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,20 @@ export default function Home({ params: { lng } }: { params: { lng: string } }) {

// TODO also add this to login logic or after email verification to prevent extra redirect?
// if the user doesn't have a default inventory or if path has a null inventory id, redirect to onboarding page
if (!inventoryId && !defaultInventoryId) {
// fixes warning "Cannot update a component (`Router`) while rendering a different component (`Home`)"
setTimeout(() => router.push(`/onboarding`), 0);
if (!inventoryId) {
if (defaultInventoryId) {
inventoryId = defaultInventoryId;
// fix inventoryId in URL without reloading page
const newPath = "/" + lng + "/" + inventoryId;
history.replaceState(null, "", newPath);

} else {
// fixes warning "Cannot update a component (`Router`) while rendering a different component (`Home`)"
setTimeout(() => router.push(`/onboarding`), 0);
}
}
}

const { data: inventory, isLoading: isInventoryLoading } =
api.useGetInventoryQuery(inventoryId!, {
skip: !inventoryId,
Expand All @@ -122,7 +131,7 @@ export default function Home({ params: { lng } }: { params: { lng: string } }) {
{ cityId: inventory?.cityId!, year: inventory?.year! },
{ skip: !inventory?.cityId || !inventory?.year },
);

let totalProgress = 0,
thirdPartyProgress = 0,
uploadedProgress = 0;
Expand Down Expand Up @@ -389,7 +398,7 @@ export default function Home({ params: { lng } }: { params: { lng: string } }) {
<Box>
<Box className="flex gap-1">
{inventory?.city.area === null ||
inventory?.city.area! === 0 ? (
inventory?.city.area! === 0 ? (
<Text
fontFamily="heading"
color="border.neutral"
Expand Down

0 comments on commit 9ee18ee

Please sign in to comment.