Skip to content

Commit ccd89d0

Browse files
Client panel: Inbox
Starting with a hardcoded welcome message. It will be turned into an onboarding process manager and Communication BC. After CustomerRegistered we will issue the command with message.
1 parent 5aa43f8 commit ccd89d0

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Client
2+
class InboxController < BaseController
3+
4+
def index
5+
render html: ClientInbox::Rendering::InboxList.build(view_context, cookies[:client_id]), layout: true
6+
end
7+
end
8+
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
require 'ostruct'
2+
3+
module ClientInbox
4+
module Rendering
5+
class InboxList < Arbre::Component
6+
include Rails.application.routes.url_helpers
7+
8+
def self.build(view_context, client_id)
9+
new(Arbre::Context.new(nil, view_context)).build(dummy_messages)
10+
end
11+
12+
def self.dummy_messages
13+
[
14+
OpenStruct.new(
15+
id: 1,
16+
title: "Welcome to our platform!",
17+
created_at: 2.days.ago,
18+
read: false
19+
)
20+
]
21+
end
22+
23+
def build(messages, attributes = {})
24+
super(attributes)
25+
26+
div class: "max-w-6xl mx-auto py-6 sm:px-6 lg:px-8" do
27+
inbox_header
28+
messages_list(messages)
29+
end
30+
end
31+
32+
private
33+
34+
def inbox_header
35+
h1 class: "text-3xl font-bold text-gray-900 mb-6" do
36+
"Your Inbox"
37+
end
38+
end
39+
40+
def messages_list(messages)
41+
return no_messages_message if messages.empty?
42+
43+
div class: "bg-white shadow rounded-lg overflow-hidden" do
44+
ul class: "divide-y divide-gray-200" do
45+
messages.each do |message|
46+
li class: "p-4 hover:bg-gray-50 transition duration-150" do
47+
message_item(message)
48+
end
49+
end
50+
end
51+
end
52+
end
53+
54+
def message_item(message)
55+
div class: "flex items-start justify-between" do
56+
div class: "flex-1" do
57+
h3 class: message_title_classes(message) do
58+
message.title
59+
end
60+
61+
span class: "text-sm text-gray-500" do
62+
time_ago_in_words(message.created_at) + " ago"
63+
end
64+
end
65+
66+
unread_indicator if !message.read
67+
end
68+
end
69+
70+
def message_title_classes(message)
71+
message.read ? "text-gray-700 text-lg" : "font-bold text-gray-900 text-lg"
72+
end
73+
74+
def unread_indicator
75+
div class: "ml-2 flex-shrink-0" do
76+
span class: "inline-block h-2 w-2 rounded-full bg-blue-600"
77+
end
78+
end
79+
80+
def no_messages_message
81+
div class: "bg-white shadow rounded-lg p-6 text-center text-gray-500" do
82+
"You have no messages"
83+
end
84+
end
85+
end
86+
end
87+
end
88+

rails_application/app/views/application/_client_top_navigation.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<div class="ml-10 flex items-baseline space-x-4">
1212
<%= navigation_link "Client View", clients_path %>
1313
<%= navigation_link "Products", client_products_path %>
14+
<%= navigation_link "Inbox", client_inbox_path %>
1415
</div>
1516
</div>
1617
</div>

rails_application/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
get :logout, to: "client/clients#logout"
6060
get "clients", to: "client/clients#index"
6161
get "client/products", to: "client/products#index"
62+
get "client/inbox", to: "client/inbox#index"
6263

6364
mount RailsEventStore::Browser => "/res"
6465
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require_relative "../test_helper"
2+
3+
class ClientInboxTest < InMemoryRESIntegrationTestCase
4+
def test_customer_sees_inbox_messages
5+
customer_id = register_customer("Test Customer")
6+
login(customer_id)
7+
get "/client/inbox"
8+
9+
assert_response :success
10+
assert_select "h1", "Your Inbox"
11+
12+
assert_message("Welcome to our platform!", /\d+ days? ago/)
13+
end
14+
15+
private
16+
17+
def assert_message(title, timestamp)
18+
assert_select "h3.font-bold.text-gray-900.text-lg", title
19+
assert_select "span.text-sm.text-gray-500", timestamp
20+
assert_select "span.inline-block.h-2.w-2.rounded-full.bg-blue-600"
21+
end
22+
23+
end
24+

0 commit comments

Comments
 (0)