Skip to content

Commit

Permalink
feat: add spotify email during sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher2K committed Nov 28, 2024
1 parent f293ac1 commit 898763f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
6 changes: 4 additions & 2 deletions swapify_api/lib/swapify_api/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ defmodule SwapifyApi.Accounts.User do
password: String.t(),
inserted_at: DateTime.t(),
updated_at: DateTime.t(),
role: user_role()
role: user_role(),
spotify_account_email: String.t() | nil
}

schema "users" do
field :email, :string
field :password, :string
field :username, :string
field :role, Ecto.Enum, values: [:beta, :user, :admin], default: :user
field :spotify_account_email, :string
has_many :platform_connections, PlatformConnection

timestamps(type: :utc_datetime)
Expand All @@ -36,7 +38,7 @@ defmodule SwapifyApi.Accounts.User do
@doc "Changaset user to create a new user"
def create_changeset(user, attrs) do
user
|> cast(attrs, [:email, :password, :username, :role])
|> cast(attrs, [:email, :password, :username, :role, :spotify_account_email])
|> validate_required([:email, :password, :username])
|> validate_format(:email, ~r/@/)
|> validate_password()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{"Email", @user.email},
{"Username", @user.username},
{"Role", @user.role},
{"Registered at", @user.inserted_at}
{"Registered at", @user.inserted_at},
{"Spotify email for beta", @user.spotify_account_email}
]} />
</section>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule SwapifyApi.Repo.Migrations.AddOptionalSpotifyEmail do
use Ecto.Migration

def change do
alter table(:users) do
add :spotify_account_email, :string, null: true
end
end
end
11 changes: 10 additions & 1 deletion swapify_web/src/features/auth/components/sign-up-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { PasswordSchema, SchemaForm } from "#root/components/schema-form";
export const SIGN_UP_FORM_ID = "sign-up-form";

const SignUpFormSchema = z.object({
username: z.string().describe("Username // e.g. llCoolChris_"),
username: z.string().min(2).max(20).describe("Username // e.g. llCoolChris_"),
email: z.string().email().describe("Email // e.g. [email protected]"),
password: PasswordSchema.describe("Password"),
spotifyAccountEmail: z
.string()
.email()
.optional()
.describe("Spotify account email"),
});
export type SignUpFormData = z.infer<typeof SignUpFormSchema>;

Expand All @@ -28,6 +33,10 @@ export function SignUpForm({ isLoading, handleSubmit, form }: SignUpFormProps) {
password: {
helperText: "Password must be at least 8 characters",
},
spotifyAccountEmail: {
helperText:
"We need your Spotify account email for the beta program, since Spotify has not approved out app yet!",
},
}}
onSubmit={handleSubmit}
formProps={{
Expand Down
7 changes: 6 additions & 1 deletion swapify_web/src/features/auth/page-signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export function PageSignup() {

async function handleSubmit(data: SignUpFormData) {
try {
await signUpAsync({ body: data });
await signUpAsync({
body: {
...data,
spotify_account_email: data.spotifyAccountEmail,
},
});
navigate({ to: "/app/sign-in", search: { from: "sign-up" } });
} catch (_) {}
}
Expand Down
1 change: 1 addition & 0 deletions swapify_web/src/services/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const APISignupPayloadSchema = z.object({
username: z.string(),
email: z.string(),
password: z.string(),
spotify_account_email: z.string().optional(),
});
export type APISignupPayload = z.infer<typeof APISignupPayloadSchema>;

Expand Down

0 comments on commit 898763f

Please sign in to comment.