Organization.utils.ts34 lines · main
| 1 | /** |
| 2 | * Builds an org-scoped URL for the wildcard org route (/org/_). |
| 3 | * |
| 4 | * When `slug` is undefined the destination is the org project list at |
| 5 | * /org/<orgSlug>. When `slug` is an array the sub-path is preserved so the |
| 6 | * user lands on the equivalent page for the chosen org. |
| 7 | */ |
| 8 | export function buildOrgUrl({ |
| 9 | slug, |
| 10 | orgSlug, |
| 11 | queryString, |
| 12 | }: { |
| 13 | slug: string | string[] | undefined |
| 14 | orgSlug: string |
| 15 | queryString: string |
| 16 | }): string { |
| 17 | const qs = queryString ? `?${queryString}` : '' |
| 18 | if (!Array.isArray(slug)) { |
| 19 | return `/org/${orgSlug}${qs}` |
| 20 | } |
| 21 | const slugPath = slug.reduce((a: string, b: string) => `${a}/${b}`, '').slice(1) |
| 22 | return `/org/${orgSlug}/${slugPath}${qs}` |
| 23 | } |
| 24 | |
| 25 | // Invite is expired if older than 24hrs |
| 26 | export function isInviteExpired(timestamp: string) { |
| 27 | const inviteDate = new Date(timestamp) |
| 28 | const now = new Date() |
| 29 | const timeBetween = now.valueOf() - inviteDate.valueOf() |
| 30 | if (timeBetween / 1000 / 60 / 60 < 24) { |
| 31 | return false |
| 32 | } |
| 33 | return true |
| 34 | } |