-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: 1_infra
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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?
app/src/components/Provinces.tsx
Outdated
export const getProvincesWithNA: () => Province[] = () => { | ||
return provinces.concat({ | ||
label: "N/A", | ||
id: "na", | ||
region: "N/A", | ||
region_id: "na", | ||
}); | ||
}; | ||
|
||
export const getProvinces = () => { | ||
return provinces; | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
export const signIn = () => { | ||
window.location.assign(new URL("/login", API_BASE_URL)); | ||
}; | ||
|
||
export const signOut = () => { | ||
window.location.assign(new URL("/logout", API_BASE_URL)); | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.)
There was a problem hiding this 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
.
case "HIDE_ALERT": | ||
return { | ||
...state, | ||
alert: false, | ||
}; |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
) || { | ||
label: "N/A", | ||
id: "na", | ||
region: "N/A", | ||
region_id: "na", | ||
}; |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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:
const defaultDOB = user?.dob ? dayjs(user.dob) : dayjs("2022-01-01"); | |
const defaultDOB = dayjs(user?.dob ?? "2022-01-01"); |
let tmpChipData = []; | ||
for (let i = 0; i < user.roles.length; i++) { | ||
tmpChipData.push({ key: i, label: user.roles[i] }); | ||
} |
There was a problem hiding this comment.
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
.)
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`, |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.)
app/src/components/Provinces.tsx
Outdated
export const getProvincesWithNA: () => Province[] = () => { | ||
return provinces.concat({ | ||
label: "N/A", | ||
id: "na", | ||
region: "N/A", | ||
region_id: "na", | ||
}); | ||
}; | ||
|
||
export const getProvinces = () => { | ||
return provinces; | ||
}; |
There was a problem hiding this comment.
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.
export const signIn = () => { | ||
window.location.assign(new URL("/login", API_BASE_URL)); | ||
}; | ||
|
||
export const signOut = () => { | ||
window.location.assign(new URL("/logout", API_BASE_URL)); | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?).
if (province != null) { | ||
console.log(ranking); | ||
if (province.id === "qc") { | ||
console.log("Vive le Québec libre!"); | ||
} | ||
} |
There was a problem hiding this comment.
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 || |
There was a problem hiding this comment.
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) ...
?
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: