Organization.utils.ts 987 B

12345678910111213141516171819202122232425262728293031323334
  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. // Invite is expired if older than 24hrs
  25. export function isInviteExpired(timestamp: string) {
  26. const inviteDate = new Date(timestamp)
  27. const now = new Date()
  28. const timeBetween = now.valueOf() - inviteDate.valueOf()
  29. if (timeBetween / 1000 / 60 / 60 < 24) {
  30. return false
  31. }
  32. return true
  33. }