Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion console/public/templates/users.csv
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
external_id,email,phone,timezone,locale
external_id,email,phone,timezone,locale
user-1,user1@example.com,+1234567890,Europe/Amsterdam,en
user-2,user2@example.com,+1234567891,America/New_York,en
user-3,user3@example.com,+1234567892,GMT+2,en
user-4,user4@example.com,+1234567893,GMT-5,en
user-5,user5@example.com,+1234567894,UTC+8,en
user-6,user6@example.com,+1234567895,EST,en
user-7,user7@example.com,+1234567896,PST,en
user-8,user8@example.com,+1234567897,CET,en
user-9,user9@example.com,+1234567898,IST,en
user-10,user10@example.com,+1234567899,Asia/Tokyo,en
64 changes: 56 additions & 8 deletions console/src/views/users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
Upload,
Mail,
Database,
Check,
} from "lucide-react"
import { UserImportDialog } from "@/components/ui/user-import-dialog"
import { NIL } from "uuid"
import { useRoute } from "@/hooks/use-route"
import { useResolver } from "../../hooks"
import { formatDate } from "../../utils"
import { formatDate, cn } from "../../utils"
import { getRandomColor } from "@/lib/colors"
import { getUserDisplayName, getUserInitials, getPrimaryExternalId } from "@/lib/name"
import { PreferencesContext } from "@/contexts/PreferencesContext"
Expand Down Expand Up @@ -45,6 +46,15 @@
} from "@/components/ui/dialog"
import { Label } from "@/components/ui/label"
import { Skeleton } from "@/components/ui/skeleton"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command"
import { AttributeEditor } from "@/components/ui/attribute-editor"
import { LocalePicker } from "@/components/locale/picker"

Expand Down Expand Up @@ -86,6 +96,7 @@
const [newUserExternalId, setNewUserExternalId] = useState("")
const [newUserEmail, setNewUserEmail] = useState("")
const [newUserPhone, setNewUserPhone] = useState("")
const [isNewUserTimezoneOpen, setIsNewUserTimezoneOpen] = useState(false)
const [newUserTimezone, setNewUserTimezone] = useState(
() => Intl.DateTimeFormat().resolvedOptions().timeZone,
)
Expand Down Expand Up @@ -449,13 +460,50 @@
</div>
<div className="grid sm:grid-cols-2 gap-4">
<div className="grid gap-2 content-start">
<Label htmlFor="timezone">{t("timezone")}</Label>
<Input
id="timezone"
placeholder={t("enter_timezone", "e.g., America/New_York")}
value={newUserTimezone}
onChange={(e) => setNewUserTimezone(e.target.value)}
/>
<Label>{t("timezone")}</Label>
<Popover open={isNewUserTimezoneOpen} onOpenChange={setIsNewUserTimezoneOpen}>

Check warning on line 464 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `·open={isNewUserTimezoneOpen}·onOpenChange={setIsNewUserTimezoneOpen}` with `⏎····································open={isNewUserTimezoneOpen}⏎····································onOpenChange={setIsNewUserTimezoneOpen}⏎································`
<PopoverTrigger asChild>
<Button
variant="outline"
role="combobox"
className="justify-between"
>
{newUserTimezone || t("select_timezone", "Select timezone")}

Check warning on line 471 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎···············································`
</Button>
Comment on lines +463 to +472
</PopoverTrigger>
<PopoverContent className="w-72 p-0" align="start">
<Command>
<CommandInput placeholder={t("search_timezone", "Search timezone...")} />

Check warning on line 476 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `·placeholder={t("search_timezone",·"Search·timezone...")}` with `⏎················································placeholder={t(⏎····················································"search_timezone",⏎····················································"Search·timezone...",⏎················································)}⏎···········································`
<CommandList>
<CommandEmpty>
{t("no_timezone_found", "No timezone found.")}
</CommandEmpty>
<CommandGroup>
{Intl.supportedValuesOf("timeZone").map((tz) => (

Check warning on line 482 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎························································`
<CommandItem

Check warning on line 483 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `························································` with `····························································`
key={tz}

Check warning on line 484 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
value={tz}

Check warning on line 485 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
onSelect={() => {

Check warning on line 486 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
setNewUserTimezone(tz)

Check warning on line 487 in console/src/views/users/Users.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `····`
setIsNewUserTimezoneOpen(false)
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
newUserTimezone === tz
? "opacity-100"
: "opacity-0",
)}
/>
{tz}
</CommandItem>
))}
</CommandGroup>
</CommandList>
Comment on lines +481 to +503
</Command>
</PopoverContent>
</Popover>
</div>
<div className="grid gap-2 content-start">
<Label>{t("locale.singular")}</Label>
Expand Down
8 changes: 8 additions & 0 deletions docs/content/docs/lists.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ user_003,carol@example.com,Carol,Initech,organic

All other columns become custom properties on the user.

<Callout type="info">
**Timezone auto-conversion**: Values in the `timezone` column are automatically
resolved to IANA timezone names. Abbreviations like `EST`, `PST`, `CET` and
GMT/UTC offsets like `GMT-5` or `+02:00` are converted to their IANA equivalents
(e.g., `America/New_York`, `America/Los_Angeles`). IANA names like
`America/New_York` are used as-is.
Comment on lines +143 to +145
</Callout>

### Updating via API

For newsletter signups or other integrations, use the Admin API to add users to a static list:
Expand Down
8 changes: 8 additions & 0 deletions docs/content/docs/users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ The `identifier` column is required and is used as the `external_id` with the `d

All other columns (like `plan` and `company` above) become custom properties.

<Callout type="info">
**Timezone auto-conversion**: Values in the `timezone` column are automatically
resolved to IANA timezone names. Abbreviations like `EST`, `PST`, `CET` and
GMT/UTC offsets like `GMT-5` or `+02:00` are converted to their IANA equivalents
(e.g., `America/New_York`, `America/Los_Angeles`). IANA names like
`America/New_York` are used as-is.
Comment on lines +272 to +274
</Callout>

<Callout type="info">
Importing via a [static list](/lists#static-lists) also creates users, but
adds them to the list. Direct CSV imports only create or update profiles.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ require (
github.com/timonwong/loggercheck v0.10.1 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tkuchiki/go-timezone v0.2.3 // indirect
github.com/tomarrell/wrapcheck/v2 v2.10.0 // indirect
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
github.com/ultraware/funlen v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
github.com/tkuchiki/go-timezone v0.2.3 h1:D3TVdIPrFsu9lxGxqNX2wsZwn1MZtTqTW0mdevMozHc=
github.com/tkuchiki/go-timezone v0.2.3/go.mod h1:oFweWxYl35C/s7HMVZXiA19Jr9Y0qJHMaG/J2TES4LY=
github.com/tomarrell/wrapcheck/v2 v2.10.0 h1:SzRCryzy4IrAH7bVGG4cK40tNUhmVmMDuJujy4XwYDg=
github.com/tomarrell/wrapcheck/v2 v2.10.0/go.mod h1:g9vNIyhb5/9TQgumxQyOEqDHsmGYcGsVMOx/xGkqdMo=
github.com/tommy-muehle/go-mnd/v2 v2.5.1 h1:NowYhSdyE/1zwK9QCLeRb6USWdoif80Ie+v+yU8u1Zw=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
email,phone,timezone,locale,external_id
user1@example.com,+1234567890,UTC,en,user-1
user2@example.com,+1234567891,UTC,en,user-2
user3@example.com,+1234567892,UTC,en,user-3
user1@example.com,+1234567890,GMT+2,en,user-1
user2@example.com,+1234567891,UTC-5,en,user-2
user3@example.com,+1234567892,PST,en,user-3
6 changes: 3 additions & 3 deletions internal/http/controllers/v1/management/test/users/valid.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
external_id,email,phone,timezone,locale
user-1,user1@example.com,+1234567890,UTC,en
user-2,user2@example.com,+1234567891,UTC,en
user-3,user3@example.com,+1234567892,UTC,en
user-1,user1@example.com,+1234567890,Europe/Amsterdam,en
user-2,user2@example.com,+1234567891,GMT-5,en
user-3,user3@example.com,+1234567892,EST,en
15 changes: 11 additions & 4 deletions internal/importer/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"strings"

"github.com/lunogram/platform/internal/pkg/timezone"
"github.com/lunogram/platform/internal/store/subjects"
)

Expand All @@ -13,10 +14,16 @@ var UserFieldMap = map[string]func(*subjects.UpsertUserParams, string){
"external_id": func(u *subjects.UpsertUserParams, v string) {
u.Identifiers = append(u.Identifiers, subjects.ExternalIDParam{Source: "default", ExternalID: v})
},
"email": func(u *subjects.UpsertUserParams, v string) { u.Email = &v },
"phone": func(u *subjects.UpsertUserParams, v string) { u.Phone = &v },
"timezone": func(u *subjects.UpsertUserParams, v string) { u.Timezone = &v },
"locale": func(u *subjects.UpsertUserParams, v string) { u.Locale = &v },
"email": func(u *subjects.UpsertUserParams, v string) { u.Email = &v },
"phone": func(u *subjects.UpsertUserParams, v string) { u.Phone = &v },
"timezone": func(u *subjects.UpsertUserParams, v string) {
if resolved, err := timezone.Resolve(v); err == nil {
u.Timezone = &resolved
} else {
u.Timezone = &v
}
},
"locale": func(u *subjects.UpsertUserParams, v string) { u.Locale = &v },
}

func NewUsers(headers []string) (*UserMapper, error) {
Expand Down
20 changes: 20 additions & 0 deletions internal/importer/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ func TestUserMapperMapRecord(t *testing.T) {
require.Empty(t, user.Data)
},
},
"timezone GMT offset conversion": {
headers: []string{"external_id", "timezone"},
record: []string{"user-gmt", "GMT+2"},
validate: func(t *testing.T, user subjects.UpsertUserParams) {
require.Len(t, user.Identifiers, 1)
require.Equal(t, "user-gmt", user.Identifiers[0].ExternalID)
require.NotNil(t, user.Timezone)
require.Equal(t, "Europe/Amsterdam", *user.Timezone)
},
},
"timezone IANA passthrough": {
headers: []string{"external_id", "timezone"},
record: []string{"user-iana", "America/New_York"},
validate: func(t *testing.T, user subjects.UpsertUserParams) {
require.Len(t, user.Identifiers, 1)
require.Equal(t, "user-iana", user.Identifiers[0].ExternalID)
require.NotNil(t, user.Timezone)
require.Equal(t, "America/New_York", *user.Timezone)
},
},
"empty values": {
headers: []string{"external_id", "email", "phone"},
record: []string{"user-empty", "", ""},
Expand Down
Loading
Loading