Repository navigation
feat(azure): change member IDs and choose the new member's address #95
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
Merged
+610
−83
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2b077c5
feat(azure): change member IDs and choose the new member's address
viganogabriele d00f422
fix(azure): retain saved member IDs and report welcome email failures
viganogabriele 89a64fa
chore: merge current UI polish into member workflow branch
viganogabriele 4f6de0a
docs(azure): refresh screenshots after the main UI update
viganogabriele e71964f
fix(azure): validate optional notification status
viganogabriele 6300e66
chore: merge main into feat/azure-member-number
viganogabriele 82cf529
Merge remote-tracking branch 'origin/main' into feat/azure-member-number
viganogabriele b9af417
fix(azure): share email validation with endpoint
viganogabriele e4bdfe3
Merge branch 'main' into feat/azure-member-number
lorenzocorallo 9400f17
Merge branch 'main' into feat/azure-member-number
lorenzocorallo e59c46a
Merge remote-tracking branch 'origin/main' into HEAD
lorenzocorallo 6acbc18
build(deps): use @polinetwork/backend 2.3.0 for the member number API
lorenzocorallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,54 @@ | ||
| import { createServerFn } from "@tanstack/react-start" | ||
| import { z } from "zod" | ||
|
|
||
| import { azureMembersCreateMiddleware, azureMembersReadMiddleware } from "@/server/auth.middleware" | ||
| import { azureEmailSchema } from "@/features/azure/email" | ||
| import { | ||
| azureMembersCreateMiddleware, | ||
| azureMembersReadMiddleware, | ||
| azureMembersWriteMiddleware, | ||
| } from "@/server/auth.middleware" | ||
|
|
||
| export const getAzureMembers = createServerFn({ method: "GET" }) | ||
| .middleware([azureMembersReadMiddleware]) | ||
| .handler(({ context }) => context.backend.azure.members.getAll.query()) | ||
|
|
||
| const setMemberNumberResultSchema = z.object({ | ||
| error: z.string().nullable(), | ||
| notificationSent: z.boolean().nullable().optional(), | ||
| }) | ||
|
|
||
| export const createAzureMember = createServerFn({ method: "POST" }) | ||
| .middleware([azureMembersCreateMiddleware]) | ||
| .validator( | ||
| z.object({ | ||
| firstName: z.string().trim().min(1), | ||
| lastName: z.string().trim().min(1), | ||
| assocNumber: z.number().int().positive(), | ||
| sendEmailTo: z.email(), | ||
| sendEmailTo: azureEmailSchema, | ||
| mailbox: z.discriminatedUnion("kind", [ | ||
| z.object({ kind: z.literal("standard") }), | ||
| z.object({ kind: z.literal("custom"), localPart: z.string().trim().min(1) }), | ||
| ]), | ||
| }) | ||
| ) | ||
| .handler(async ({ data, context }) => { | ||
| const result = await context.backend.azure.members.create.mutate(data) | ||
| if (result.error) throw new Error(result.error) | ||
| if (result.error !== null) throw new Error(result.error) | ||
| return result | ||
| }) | ||
|
|
||
| /** Throws when the number is not saved; `notificationSent` is false when only the email failed. */ | ||
| export const setAzureMemberNumber = createServerFn({ method: "POST" }) | ||
| .middleware([azureMembersWriteMiddleware]) | ||
| .validator( | ||
| z.object({ | ||
| userId: z.string().min(1), | ||
| assocNumber: z.number().int().positive(), | ||
| notifyEmail: azureEmailSchema.optional(), | ||
| }) | ||
| ) | ||
| .handler(async ({ data, context }) => { | ||
| const result = setMemberNumberResultSchema.parse(await context.backend.azure.members.setAssocNumber.mutate(data)) | ||
| if (result.error !== null) throw new Error(result.error) | ||
| return result | ||
| }) | ||
|
lorenzocorallo marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { z } from "zod" | ||
|
|
||
| /** Shared email validation for Azure member notifications. */ | ||
| export const azureEmailSchema = z.email() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** Mirrors the backend's `src/azure/mailbox.ts`, which builds and checks the address again. */ | ||
| export const MAIL_DOMAIN = "polinetwork.org" | ||
|
|
||
| const LOCAL_PART = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/ | ||
|
|
||
| export type MailboxKind = "standard" | "custom" | ||
|
|
||
| export function isLocalPart(value: string) { | ||
| return value.length <= 64 && LOCAL_PART.test(value) | ||
| } | ||
|
|
||
| /** Accents and apostrophes are dropped and spaces removed: "Niccolò", "D'Amico" -> "niccolo.damico". */ | ||
| function namePart(name: string) { | ||
| return name.trim().normalize("NFD").replace(/\p{M}/gu, "").replace(/['\s]/g, "").toLowerCase() | ||
| } | ||
|
|
||
| /** `firstname.lastname`, or null when the name has letters an address cannot hold (e.g. "Łukasz"). */ | ||
| export function standardLocalPart(firstName: string, lastName: string): string | null { | ||
| const localPart = `${namePart(firstName)}.${namePart(lastName)}` | ||
| return isLocalPart(localPart) ? localPart : null | ||
| } | ||
|
|
||
| export function isPoliNetworkAddress(email: string) { | ||
| return email.trim().toLowerCase().endsWith(`@${MAIL_DOMAIN}`) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.