Skip to content
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

Settings and edit bio #356

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

Settings and edit bio #356

wants to merge 4 commits into from

Conversation

Steindt
Copy link
Contributor

@Steindt Steindt commented May 15, 2024

Fixes some issues with overlapping elements in the settings page on smaller screens, fixed access for settings page and edit-bio.

Screenshot of overlapping elements:
Screenshot from 2024-05-15 12-14-41

@Steindt Steindt self-assigned this May 15, 2024
Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 10:18am

@Steindt Steindt requested review from a team and alfredgrip and removed request for a team May 15, 2024 10:42
<div
class={languageTag() == "sv"
? "flex flex-col items-center md:grid md:grid-cols-2"
: "flex flex-col items-center xl:grid xl:grid-cols-2"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really the best way to do this? Feels kinda sketchy

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's pretty sketchy, the english names are usually longer than the swedish ones but it either looks pretty empty or cramped if you only have 1 of them. Could otherwise decide on a longer settings page by not having notifications beside tags, but there will be a bit more scrolling if that's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. It looks fine when I look at it, so it's not outright wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should find some solution with auto columns, min-content or something like that. We never know what the tags will have as names in the future.

@alfredgrip
Copy link
Contributor

Just pushed some changes, thought it was easier than doing a bunch of code reviewing. Let me know if you agree with my changes or not!

Copy link
Collaborator

@Macludde Macludde left a comment

Choose a reason for hiding this comment

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

Some nice things but I think a lot of this code was quite outdated before this PR and some steps can be taken to make it even better.

Comment on lines -10 to +9
authorize(apiNames.MEMBER.UPDATE, user);
if (!user || !user.memberId) throw redirect(302, "/home");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? I think it's weird to redirect someone to home screen instead of just showing error. It can make the page seem confusing

Copy link
Collaborator

Choose a reason for hiding this comment

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

You've also removed the verification that a user can actually edit this person's bio.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But I see, the old system seems to not check if params.studentId === user.studentId, in which case you should be able to edit. Otherwise you cannot edit your own bio.

Comment on lines -8 to +13
authorize(apiNames.MEMBER.UPDATE, user);

const subscriptionSettings = user
? await prisma.subscriptionSetting.findMany({
where: {
memberId: user.memberId,
},
})
: [];
if (user?.memberId == null) throw redirect(302, "/home");

const subscriptionSettings = await prisma.subscriptionSetting.findMany({
where: {
memberId: user.memberId,
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a user is not logged in, instead of redirecting them we should show an error to be clearer. This redirect doesn't make much sense. throw error(401, "Not logged in") instead (can't remember exact syntax, check other page.server.ts files or even the authorize function

Comment on lines 38 to 40
const { user, prisma } = locals;
const form = await request.formData();
if (!user) return fail(401, { form });
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should probably use zod and superforms to handle type validation, like we do in other form inputs

Comment on lines +46 to +59
const push: string[] = [];
for (const v of form.getAll("push")) {
if (typeof v !== "string") return fail(400, { form });
push.push(v);
}
const subscription: string[] = [];
for (const v of form.getAll("subscription")) {
if (typeof v !== "string") return fail(400, { form });
subscription.push(v);
}
const tags: string[] = [];
for (const v of form.getAll("tag")) {
if (typeof v !== "string") return fail(400, { form });
tags.push(v);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could be replaced with three one-liners like this:
const push: string[] = form.getAll("push").filter((v) => typeof v === "string");

If we want the form to fail for invalid types, I think zod should help with that. Then we don't have to do the hack above and could just do const pus = form.data.push;

}

const memberId = user.memberId;
if (memberId == null) return fail(400, { form });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (memberId == null) return fail(400, { form });
if (memberId == null) return fail(401, { form });

Copy link
Collaborator

Choose a reason for hiding this comment

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

400 is Bad Request, ie something wrong with the form data. 401 is Unauthorized, ie not logged in.

Comment on lines +64 to +91
await prisma.subscriptionSetting.deleteMany({
where: {
memberId: memberId,
},
});
await prisma.subscriptionSetting.createMany({
data: subscription.map((sub) => {
return {
memberId: memberId,
type: sub,
pushNotification: push.find((tag) => sub == tag) ? true : false,
};
}),
});
await prisma.member.update({
where: {
id: memberId,
},
data: {
subscribedTags: {
set: tags.map((tag) => {
return {
id: tag,
};
}),
},
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably be done in a transaction in-case one of these fails. Because in that case a user might lose all their subscription settings but none would be added or something. I know this isn't written in this PR but always good to improve our code.

Also, we don't have to remove all of the user's settings, only remove the ones not in the form data.

@@ -96,7 +96,7 @@
<SubscriptionTags {tags} subscribedTags={subscribedTags.subscribedTags} />
</div>
<button
class="btn absolute bottom-0 mb-4 mt-4 w-full max-w-xl bg-primary"
class="btn absolute bottom-0 mb-4 mt-4 w-full max-w-xl bg-primary text-white"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Across the page we have white text color for buttons with primary background. I do, however, think we should btn-primary instead of bg-primary to have consequential styling across the page.

<div
class={languageTag() == "sv"
? "flex flex-col items-center md:grid md:grid-cols-2"
: "flex flex-col items-center xl:grid xl:grid-cols-2"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should find some solution with auto columns, min-content or something like that. We never know what the tags will have as names in the future.

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.

4 participants