Skip to content

Frontend part A: user facing pages #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

AlexandreOndet
Copy link
Contributor

@AlexandreOndet AlexandreOndet commented Nov 9, 2023

Merging after the infra changes is fine so it doesn't need to be in the same order as the rest of the backend

This PR contains:

  • all the frontend user facing routes
  • the text in english and french for all these pages
  • the http client to query the backend
  • the removal of webvitals
  • the updates of the dependencies

Copy link

@kr-matthews kr-matthews left a comment

Choose a reason for hiding this comment

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

Partial review - I haven't gone through Account or Rankings.
I also still don't have the repo running locally. But I assume it wouldn't work on this branch since it's just the front-end?

Comment on lines 39 to 50
export const getProvincesWithNA: () => Province[] = () => {
return provinces.concat({
label: "N/A",
id: "na",
region: "N/A",
region_id: "na",
});
};

export const getProvinces = () => {
return provinces;
};

Choose a reason for hiding this comment

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

Why are these functions, rather than directly exporting the 2 arrays as constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was to avoid having all the lines duplicated just to have one with NA and one without. I added getProvinces to make the calls coherent.
But maybe my reasoning wasn't right I don't know. I'm always trying to avoid duplicated code when I can usually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about a solution where we remove getProvinces but we keep getProvincesWithNA ?

Choose a reason for hiding this comment

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

I was thinking something like

export const provinces = [
 // the provinces
]

export const naProvince = {
  // ...
}

export const provincesWithNa = provinces.concat(naProvince)

but I might be overlooking something which prevents that from working the way I think it will.

Comment on lines +6 to +12
export const signIn = () => {
window.location.assign(new URL("/login", API_BASE_URL));
};

export const signOut = () => {
window.location.assign(new URL("/logout", API_BASE_URL));
};

Choose a reason for hiding this comment

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

Is it possible to use react navigation to get to login/logout? I think that would be better practice than editing the window location directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I tried first but for some reason it wasn't working. I agree with you that it would be more coherent to have it like the rest and I would be happy to change it if we find a way that works.

Choose a reason for hiding this comment

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

I don't recall at the moment how to change this. Maybe Jon can have a quick look when he has time.

Choose a reason for hiding this comment

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

This is a util file, not a page nor a component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is going to be the Admin page in the part B PR (#79 ) so that's why the file is named that way

Choose a reason for hiding this comment

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

It might be worth keeping this isAdmin in a separate util file anyway, if it's going to be used in multiple components.
(I haven't looked at PR B yet.)

Copy link

@kr-matthews kr-matthews left a comment

Choose a reason for hiding this comment

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

I reviewed Account. Still haven't looked closely at Rankings.

Comment on lines +50 to +54
case "HIDE_ALERT":
return {
...state,
alert: false,
};

Choose a reason for hiding this comment

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

Might as well reset the alert to initialState, to avoid having the old type/content state hanging around and accidentally being revealed later.


const initialState: AlertState = {
alert: false,
alertType: "error",

Choose a reason for hiding this comment

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

Is there a more neutral option we could use as the initial/default state?

Comment on lines +77 to +82
) || {
label: "N/A",
id: "na",
region: "N/A",
region_id: "na",
};

Choose a reason for hiding this comment

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

This is copy-pasted from the provinces.

region: "N/A",
region_id: "na",
};
const defaultDOB = user?.dob ? dayjs(user.dob) : dayjs("2022-01-01");

Choose a reason for hiding this comment

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

Can we have a null default, or does this need to be a date? If it does need to be a date, then:

Suggested change
const defaultDOB = user?.dob ? dayjs(user.dob) : dayjs("2022-01-01");
const defaultDOB = dayjs(user?.dob ?? "2022-01-01");

Comment on lines +117 to +120
let tmpChipData = [];
for (let i = 0; i < user.roles.length; i++) {
tmpChipData.push({ key: i, label: user.roles[i] });
}

Choose a reason for hiding this comment

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

Generally in React, using something like map would be preferable to pushing to a variable. (And even as the code is, tmpChipData can be a const, it doesn't need to be a let.)

Suggested change
let tmpChipData = [];
for (let i = 0; i < user.roles.length; i++) {
tmpChipData.push({ key: i, label: user.roles[i] });
}
const chipData = user.roles.map((role) => ({ key: role, label: role }))

(I'm not 100% this is equivalent, but something like this.)

format="DD-MM-YYYY"
InputProps={{
style: {
width: `${defaultEmail.length * 10 > 280 ? 145 : 280}px`,

Choose a reason for hiding this comment

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

Is the date field width meant to depend on the default email length?
It feels a bit weird to specify the width of input elements based on the default values. What exactly is the problem with fixed width?

component="ul"
>
{chipData.map((data) => {
const color: chipColor | undefined =

Choose a reason for hiding this comment

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

This will always be a chipColor right? ie never undefined

Choose a reason for hiding this comment

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

It might be worth keeping this isAdmin in a separate util file anyway, if it's going to be used in multiple components.
(I haven't looked at PR B yet.)

Comment on lines 39 to 50
export const getProvincesWithNA: () => Province[] = () => {
return provinces.concat({
label: "N/A",
id: "na",
region: "N/A",
region_id: "na",
});
};

export const getProvinces = () => {
return provinces;
};

Choose a reason for hiding this comment

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

I was thinking something like

export const provinces = [
 // the provinces
]

export const naProvince = {
  // ...
}

export const provincesWithNa = provinces.concat(naProvince)

but I might be overlooking something which prevents that from working the way I think it will.

Comment on lines +6 to +12
export const signIn = () => {
window.location.assign(new URL("/login", API_BASE_URL));
};

export const signOut = () => {
window.location.assign(new URL("/logout", API_BASE_URL));
};

Choose a reason for hiding this comment

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

I don't recall at the moment how to change this. Maybe Jon can have a quick look when he has time.

Copy link

@kr-matthews kr-matthews left a comment

Choose a reason for hiding this comment

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

I've reviewed everything now, but I haven't run locally (but I assume it won't do anything without the backend PRs anyway?).

Comment on lines +71 to +76
if (province != null) {
console.log(ranking);
if (province.id === "qc") {
console.log("Vive le Québec libre!");
}
}

Choose a reason for hiding this comment

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

I'd be in favour of removing these.

if (
eventId === null ||
province?.id === null ||
usingAverage === null ||

Choose a reason for hiding this comment

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

Isn't usingAverage always a boolean?
Can the conditional be simplified to if (!eventId || !province?.id) ...?

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

Successfully merging this pull request may close these issues.

2 participants