@@ -4,13 +4,35 @@ defmodule AlgoraWeb.Org.JobLive do
4
4
5
5
alias Algora.Accounts.User
6
6
alias Algora.Jobs
7
+ alias Algora.Repo
7
8
alias Algora.Settings
8
9
alias AlgoraWeb.Forms.BountyForm
9
10
alias AlgoraWeb.Forms.ContractForm
10
11
alias AlgoraWeb.Forms.TipForm
11
12
12
13
require Logger
13
14
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
+
14
36
defp subscribe ( job ) do
15
37
Phoenix.PubSub . subscribe ( Algora.PubSub , "job:#{ job . id } " )
16
38
end
@@ -45,6 +67,21 @@ defmodule AlgoraWeb.Org.JobLive do
45
67
# Map of github_handle => %{status: :loading/:done, user: nil/User}
46
68
|> assign ( :importing_users , % { } )
47
69
|> 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
+ )
48
85
|> assign_applicants ( ) }
49
86
50
87
_ ->
@@ -649,12 +686,31 @@ defmodule AlgoraWeb.Org.JobLive do
649
686
end
650
687
651
688
@ 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" ] ) 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
658
714
end
659
715
660
716
@ impl true
@@ -1587,6 +1643,45 @@ defmodule AlgoraWeb.Org.JobLive do
1587
1643
{ Money . to_string! ( @ current_org . subscription_price ) }
1588
1644
</ span >
1589
1645
</ 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 >
1590
1685
</ div >
1591
1686
< p class = "text-sm text-muted-foreground pt-4 " >
1592
1687
You will receive an invoice and receipt via email once you confirm
0 commit comments