Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Added features to success page #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Added features to success page #7

wants to merge 3 commits into from

Conversation

brandontiu
Copy link
Collaborator

The order id is now included on the success page along with the button to redirect to the order page. The page is also set to automatically redirect to the order page after 7 seconds regardless using SetTimeout.

Screen.Recording.2022-01-07.at.2.16.19.PM.mov

@brandontiu brandontiu requested a review from ralph-dev January 7, 2022 19:27
Copy link
Member

@ralph-dev ralph-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little more improvements needed

@@ -23,10 +30,12 @@ export const CheckoutForm = (): React.ReactElement => {
return;
}

const successURL = "http://localhost:8080/checkout?id=".concat(orderId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an ENV variable for this since production != development URL


export const Success: React.VFC = () => {
const [orderId, setOrderId] = useState<string>("");
const router = useRouter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no typing needed here like <url: string>
Might reduce the need for AS below

const router = useRouter();

useEffect(() => {
const orderIdString: string = router.query.id as string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As string is usually something you want to avoid if you can

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used to get around this typescript error, "Type 'string[]' is not assignable to type 'string'." Would this be a case where it is something we can't avoid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you do [0] to grab the first string in the index since that's what it is? Just becuase the override the type doesn't override the underlying JavaScript structure. This will lead to confusion down the road ;).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried getting the element at index 0 I would only get the first char in the order id which made me think that the id should be a string but for some reason its being identified as an array of string by typescript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let's take a look during our meeting. In the meantime I would suggest looking at the typing for Router for the entire application as the answer will probs be there.

Also try removing as string and seeing if the error goes away

}, [router.query]);

useEffect(() => {
const timer = setTimeout(() => window.location.replace("/order"), 7000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7000 is a magic number

@@ -16,6 +34,11 @@ export const Success: React.VFC = () => {
textAlign: "center",
};

const buttonProps = {
color: "red",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in styled component

@@ -16,6 +34,11 @@ export const Success: React.VFC = () => {
textAlign: "center",
};

const buttonProps = {
color: "red",
onClick: () => window.location.replace("/order"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just create a function


const StyledButton = styled(Button)`
margin-left: auto;
margin-right: auto;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use margin short form notation

Copy link
Member

@ralph-dev ralph-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Great fixes so far

Comment on lines 15 to 20
declare var process: {
env: {
BASE_URL: string;
};
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be very tedious for you to declare this everywhere you use process. Have an index.d.TS file

D stands for definitions

@@ -23,10 +36,12 @@ export const CheckoutForm = (): React.ReactElement => {
return;
}

const successURL = process.env.BASE_URL + "/checkout?id=".concat(orderId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a template literal instead.

}

useEffect(() => {
const duration = 7000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Const at top of the file, no need to redeclare.
Duration is a bad variable name.
What is the meaning! The meaning is
SESSION_EXPIRY_TIMEOUT = 7000;
Much more intitutife when you read the variable versus just 7000

Comment on lines 40 to 42
const buttonProps = {
onClick: newOrder,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and just pass it inline

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants