@@ -4,13 +4,35 @@ defmodule AlgoraWeb.Org.JobLive do
44
55 alias Algora.Accounts.User
66 alias Algora.Jobs
7+ alias Algora.Repo
78 alias Algora.Settings
89 alias AlgoraWeb.Forms.BountyForm
910 alias AlgoraWeb.Forms.ContractForm
1011 alias AlgoraWeb.Forms.TipForm
1112
1213 require Logger
1314
15+ defmodule WirePaymentForm do
16+ @ moduledoc false
17+ use Ecto.Schema
18+
19+ import Ecto.Changeset
20+
21+ embedded_schema do
22+ field :billing_name , :string
23+ field :billing_address , :string
24+ field :executive_name , :string
25+ field :executive_role , :string
26+ field :payment_date , :date
27+ end
28+
29+ def changeset ( form , attrs \\ % { } ) do
30+ form
31+ |> cast ( attrs , [ :billing_name , :billing_address , :executive_name , :executive_role , :payment_date ] )
32+ |> validate_required ( [ :billing_name , :billing_address , :executive_name , :executive_role , :payment_date ] )
33+ end
34+ end
35+
1436 defp subscribe ( job ) do
1537 Phoenix.PubSub . subscribe ( Algora.PubSub , "job:#{ job . id } " )
1638 end
@@ -45,6 +67,21 @@ defmodule AlgoraWeb.Org.JobLive do
4567 # Map of github_handle => %{status: :loading/:done, user: nil/User}
4668 |> assign ( :importing_users , % { } )
4769 |> assign ( :loading_contribution_handle , nil )
70+ |> assign (
71+ :wire_form ,
72+ to_form (
73+ WirePaymentForm . changeset (
74+ % WirePaymentForm {
75+ payment_date: Date . utc_today ( ) ,
76+ billing_name: socket . assigns . current_org . billing_name ,
77+ billing_address: socket . assigns . current_org . billing_address ,
78+ executive_name: socket . assigns . current_org . executive_name ,
79+ executive_role: socket . assigns . current_org . executive_role
80+ } ,
81+ % { }
82+ )
83+ )
84+ )
4885 |> assign_applicants ( ) }
4986
5087 _ ->
@@ -649,12 +686,31 @@ defmodule AlgoraWeb.Org.JobLive do
649686 end
650687
651688 @ 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 ) }
689+ def handle_event ( "process_payment" , % { "payment" => % { "payment_type" => "wire" } } = params , socket ) do
690+ case WirePaymentForm . changeset ( % WirePaymentForm { } , params [ "wire_payment_form" ] ) do
691+ % { valid?: true } = changeset ->
692+ # Update user billing info
693+ { :ok , _user } =
694+ socket . assigns . current_org
695+ |> Ecto.Changeset . change ( % {
696+ billing_name: changeset . changes . billing_name ,
697+ billing_address: changeset . changes . billing_address ,
698+ executive_name: changeset . changes . executive_name ,
699+ executive_role: changeset . changes . executive_role
700+ } )
701+ |> Repo . update ( )
702+
703+ { :noreply ,
704+ socket
705+ |> put_flash ( :info , "Wire transfer details have been sent to your email" )
706+ |> assign ( :show_payment_drawer , false ) }
707+
708+ % { valid?: false } = changeset ->
709+ { :noreply ,
710+ socket
711+ |> assign ( :wire_form , to_form ( changeset ) )
712+ |> put_flash ( :error , "Please fill in all required fields" ) }
713+ end
658714 end
659715
660716 @ impl true
@@ -1587,9 +1643,48 @@ defmodule AlgoraWeb.Org.JobLive do
15871643 { Money . to_string! ( @ current_org . subscription_price ) }
15881644 </ span >
15891645 </ div >
1646+
1647+ < div class = "border-t pt-4 " >
1648+ < h4 class = "font-medium mb-4 " > Billing Information</ h4 >
1649+ < div class = "space-y-4 " >
1650+ < . input
1651+ type = "text "
1652+ label = "Billing Name "
1653+ field = { @ wire_form [ :billing_name ] }
1654+ value = {
1655+ @ current_org . billing_name || @ current_org . display_name ||
1656+ @ current_org . handle
1657+ }
1658+ />
1659+ < . input
1660+ type = "textarea "
1661+ label = "Billing Address "
1662+ field = { @ wire_form [ :billing_address ] }
1663+ value = { @ current_org . billing_address }
1664+ />
1665+ < . input
1666+ type = "text "
1667+ label = "Executive Name "
1668+ field = { @ wire_form [ :executive_name ] }
1669+ value = { @ current_org . executive_name }
1670+ />
1671+ < . input
1672+ type = "text "
1673+ label = "Executive Role "
1674+ field = { @ wire_form [ :executive_role ] }
1675+ value = { @ current_org . executive_role }
1676+ />
1677+ < . input
1678+ type = "date "
1679+ label = "Payment Date "
1680+ field = { @ wire_form [ :payment_date ] }
1681+ value = { Date . utc_today ( ) }
1682+ />
1683+ </ div >
1684+ </ div >
15901685 </ div >
15911686 < p class = "text-sm text-muted-foreground pt-4 " >
1592- You will receive an invoice and receipt via email once you confirm
1687+ You will receive an invoice via email once you confirm
15931688 </ p >
15941689 </ . card_content >
15951690 </ . card >
@@ -1599,7 +1694,7 @@ defmodule AlgoraWeb.Org.JobLive do
15991694 Cancel
16001695 </ . button >
16011696 < . button type = "submit " >
1602- I have wired
1697+ Generate invoice
16031698 </ . button >
16041699 </ div >
16051700 </ div >
0 commit comments