@@ -38,14 +38,25 @@ defmodule AlgoraWeb.Contract.ViewLive do
3838 < h1 class = "text-2xl font-semibold " >
3939 Contract with { @ contract . contractor . name }
4040 </ h1 >
41- < p class = "text-sm text-muted-foreground " >
42- Started { Calendar . strftime ( @ contract . start_date , "%b %d, %Y" ) }
43- </ p >
41+ <%= if @ contract . start_date do %>
42+ < p class = "text-sm text-muted-foreground " >
43+ Started { Calendar . strftime ( @ contract . start_date , "%b %d, %Y" ) }
44+ </ p >
45+ <% else %>
46+ < p class = "text-sm text-muted-foreground " >
47+ Drafted on { Calendar . strftime ( @ contract . inserted_at , "%b %d, %Y" ) }
48+ </ p >
49+ <% end %>
4450 </ div >
4551 </ div >
46- < div >
47- < . badge variant = "success " > Active</ . badge >
48- </ div >
52+ <%= case @ contract . status do %>
53+ <% :draft -> %>
54+ < . badge variant = "warning " > Draft</ . badge >
55+ <% :active - > %>
56+ < . badge variant = "success " > Active</ . badge >
57+ <% _ -> %>
58+ < . badge variant = "destructive " > Inactive</ . badge >
59+ <% end %>
4960 </ div >
5061 <!-- Stats Grid -->
5162 < div class = "mt-8 grid grid-cols-4 gap-4 " >
@@ -84,14 +95,14 @@ defmodule AlgoraWeb.Contract.ViewLive do
8495 </ . card >
8596 </ div >
8697 <!-- Tabs -->
87- < . tabs :let = { builder } id = "contract-tabs " default = "payments " class = "mt-8 " >
98+ < . tabs :let = { builder } id = "contract-tabs " default = "details " class = "mt-8 " >
8899 < . tabs_list class = "flex w-full space-x-1 rounded-lg bg-muted p-1 " >
89- < . tabs_trigger builder = { builder } value = "payments " class = "flex-1 " >
90- < . icon name = "tabler-credit-card " class = "mr-2 h-4 w-4 " /> Payments
91- </ . tabs_trigger >
92100 < . tabs_trigger builder = { builder } value = "details " class = "flex-1 " >
93101 < . icon name = "tabler-file-text " class = "mr-2 h-4 w-4 " /> Contract Details
94102 </ . tabs_trigger >
103+ < . tabs_trigger builder = { builder } value = "payments " class = "flex-1 " >
104+ < . icon name = "tabler-credit-card " class = "mr-2 h-4 w-4 " /> Payments
105+ </ . tabs_trigger >
95106 < . tabs_trigger builder = { builder } value = "activity " class = "flex-1 " >
96107 < . icon name = "tabler-history " class = "mr-2 h-4 w-4 " /> Activity
97108 </ . tabs_trigger >
@@ -106,7 +117,7 @@ defmodule AlgoraWeb.Contract.ViewLive do
106117 </ . card_description >
107118 </ . card_header >
108119 < . card_content >
109- < div class = "space-y-8 " >
120+ < div :if = { @ contract . timesheet } class = "space-y-8 " >
110121 <%= for contract <- @ contract_chain do %>
111122 <%= case Contracts . get_payment_status ( contract ) do %>
112123 <% { :pending_timesheet , contract } -> %>
@@ -119,7 +130,7 @@ defmodule AlgoraWeb.Contract.ViewLive do
119130 < div class = "font-medium " >
120131 Waiting for timesheet submission
121132 </ div >
122- < div class = "text-sm text-muted-foreground " >
133+ < div :if = { contract . start_date } class = "text-sm text-muted-foreground " >
123134 { Calendar . strftime ( contract . start_date , "%b %d" ) } - { Calendar . strftime (
124135 contract . end_date ,
125136 "%b %d, %Y"
@@ -142,7 +153,7 @@ defmodule AlgoraWeb.Contract.ViewLive do
142153 < div class = "font-medium " >
143154 Ready to release payment for { contract . timesheet . hours_worked } hours
144155 </ div >
145- < div class = "text-sm text-muted-foreground " >
156+ < div :if = { contract . start_date } class = "text-sm text-muted-foreground " >
146157 { Calendar . strftime ( contract . start_date , "%b %d" ) } - { Calendar . strftime (
147158 contract . end_date ,
148159 "%b %d, %Y"
@@ -464,19 +475,30 @@ defmodule AlgoraWeb.Contract.ViewLive do
464475 thread = Chat . get_or_create_thread! ( contract )
465476 messages = thread . id |> Chat . list_messages ( ) |> Repo . preload ( :sender )
466477
467- { :ok ,
468- socket
469- |> assign ( :contract , contract )
470- |> assign ( :contract_chain , contract_chain )
471- |> assign ( :has_more , length ( contract_chain ) >= page_size ( ) )
472- |> assign ( :page_title , "Contract with #{ contract . contractor . name } " )
473- |> assign ( :messages , messages )
474- |> assign ( :thread , thread )
475- |> assign ( :show_release_renew_modal , false )
476- |> assign ( :show_release_modal , false )
477- |> assign ( :show_dispute_modal , false )
478- |> assign ( :fee_data , Contracts . calculate_fee_data ( contract ) )
479- |> assign ( :org_members , Organizations . list_org_members ( contract . client ) ) }
478+ case socket . assigns [ :current_user ] do
479+ nil ->
480+ { :ok , redirect ( socket , to: ~p" /auth/login?return_to=#{ ~p" /org/#{ contract . client . handle } /contracts/#{ id } " } " ) }
481+
482+ current_user ->
483+ if current_user . id != contract . contractor_id and
484+ not ( socket . assigns . all_contexts |> Enum . map ( & & 1 . id ) |> Enum . member? ( contract . client_id ) ) do
485+ { :ok , raise ( AlgoraWeb.NotFoundError ) }
486+ else
487+ { :ok ,
488+ socket
489+ |> assign ( :contract , contract )
490+ |> assign ( :contract_chain , contract_chain )
491+ |> assign ( :has_more , length ( contract_chain ) >= page_size ( ) )
492+ |> assign ( :page_title , "Contract with #{ contract . contractor . name } " )
493+ |> assign ( :messages , messages )
494+ |> assign ( :thread , thread )
495+ |> assign ( :show_release_renew_modal , false )
496+ |> assign ( :show_release_modal , false )
497+ |> assign ( :show_dispute_modal , false )
498+ |> assign ( :fee_data , Contracts . calculate_fee_data ( contract ) )
499+ |> assign ( :org_members , Organizations . list_org_members ( contract . client ) ) }
500+ end
501+ end
480502 end
481503
482504 def handle_event ( "send_message" , % { "message" => content } , socket ) do
0 commit comments