@@ -11,6 +11,27 @@ defmodule AlgoraWeb.Org.JobLive do
1111
1212 require Logger
1313
14+ defmodule WirePaymentForm do
15+ @ moduledoc false
16+ use Ecto.Schema
17+
18+ import Ecto.Changeset
19+
20+ embedded_schema do
21+ field :billing_name , :string
22+ field :billing_address , :string
23+ field :executive_name , :string
24+ field :executive_role , :string
25+ field :payment_date , :date
26+ end
27+
28+ def changeset ( form , attrs \\ % { } ) do
29+ form
30+ |> cast ( attrs , [ :billing_name , :billing_address , :executive_name , :executive_role , :payment_date ] )
31+ |> validate_required ( [ :billing_name , :billing_address , :executive_name , :executive_role , :payment_date ] )
32+ end
33+ end
34+
1435 defp subscribe ( job ) do
1536 Phoenix.PubSub . subscribe ( Algora.PubSub , "job:#{ job . id } " )
1637 end
@@ -45,6 +66,14 @@ defmodule AlgoraWeb.Org.JobLive do
4566 # Map of github_handle => %{status: :loading/:done, user: nil/User}
4667 |> assign ( :importing_users , % { } )
4768 |> assign ( :loading_contribution_handle , nil )
69+ |> assign (
70+ :wire_form ,
71+ to_form (
72+ WirePaymentForm . changeset ( % WirePaymentForm {
73+ payment_date: Date . utc_today ( )
74+ } )
75+ )
76+ )
4877 |> assign_applicants ( ) }
4978
5079 _ ->
@@ -649,12 +678,31 @@ defmodule AlgoraWeb.Org.JobLive do
649678 end
650679
651680 @ impl true
652- def handle_event ( "process_payment" , % { "payment" => % { "payment_type" => "wire" } } , socket ) do
653- # Mock successful wire initiation
654- { :noreply ,
655- socket
656- |> put_flash ( :info , "Wire transfer details have been sent to your email" )
657- |> assign ( :show_payment_drawer , false ) }
681+ def handle_event ( "process_payment" , % { "payment" => % { "payment_type" => "wire" } } = params , socket ) do
682+ case WirePaymentForm . changeset ( % WirePaymentForm { } , params [ "wire_payment" ] ) do
683+ % { valid?: true } = changeset ->
684+ # Update user billing info
685+ { :ok , _user } =
686+ socket . assigns . current_org
687+ |> Ecto.Changeset . change ( % {
688+ billing_name: changeset . changes . billing_name ,
689+ billing_address: changeset . changes . billing_address ,
690+ executive_name: changeset . changes . executive_name ,
691+ executive_role: changeset . changes . executive_role
692+ } )
693+ |> Repo . update ( )
694+
695+ { :noreply ,
696+ socket
697+ |> put_flash ( :info , "Wire transfer details have been sent to your email" )
698+ |> assign ( :show_payment_drawer , false ) }
699+
700+ % { valid?: false } = changeset ->
701+ { :noreply ,
702+ socket
703+ |> assign ( :wire_form , to_form ( changeset ) )
704+ |> put_flash ( :error , "Please fill in all required fields" ) }
705+ end
658706 end
659707
660708 @ impl true
@@ -1587,6 +1635,45 @@ defmodule AlgoraWeb.Org.JobLive do
15871635 { Money . to_string! ( @ current_org . subscription_price ) }
15881636 </ span >
15891637 </ div >
1638+
1639+ < div class = "border-t pt-4 " >
1640+ < h4 class = "font-medium mb-4 " > Billing Information</ h4 >
1641+ < div class = "space-y-4 " >
1642+ < . input
1643+ type = "text "
1644+ label = "Billing Name "
1645+ field = { @ wire_form [ :billing_name ] }
1646+ value = {
1647+ @ current_org . billing_name || @ current_org . display_name ||
1648+ @ current_org . handle
1649+ }
1650+ />
1651+ < . input
1652+ type = "textarea "
1653+ label = "Billing Address "
1654+ field = { @ wire_form [ :billing_address ] }
1655+ value = { @ current_org . billing_address }
1656+ />
1657+ < . input
1658+ type = "text "
1659+ label = "Executive Name "
1660+ field = { @ wire_form [ :executive_name ] }
1661+ value = { @ current_org . executive_name }
1662+ />
1663+ < . input
1664+ type = "text "
1665+ label = "Executive Role "
1666+ field = { @ wire_form [ :executive_role ] }
1667+ value = { @ current_org . executive_role }
1668+ />
1669+ < . input
1670+ type = "date "
1671+ label = "Payment Date "
1672+ field = { @ wire_form [ :payment_date ] }
1673+ value = { Date . utc_today ( ) }
1674+ />
1675+ </ div >
1676+ </ div >
15901677 </ div >
15911678 < p class = "text-sm text-muted-foreground pt-4 " >
15921679 You will receive an invoice and receipt via email once you confirm
0 commit comments