🌐 AI搜索 & 代理 主页
Skip to content

Commit 9e90df6

Browse files
committed
subscribe use turbo frames, all unsubscribe, add module to careers page
1 parent 5a3cbce commit 9e90df6

File tree

7 files changed

+105
-38
lines changed

7 files changed

+105
-38
lines changed

pgml-dashboard/src/components/cards/newsletter_subscribe/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ use sailfish::TemplateOnce;
33

44
#[derive(TemplateOnce, Default)]
55
#[template(path = "cards/newsletter_subscribe/template.html")]
6-
pub struct NewsletterSubscribe {}
6+
pub struct NewsletterSubscribe {
7+
success: Option<bool>,
8+
error_message: Option<String>,
9+
email: Option<String>,
10+
}
711

812
impl NewsletterSubscribe {
913
pub fn new() -> NewsletterSubscribe {
10-
NewsletterSubscribe {}
14+
NewsletterSubscribe {
15+
success: None,
16+
error_message: None,
17+
email: None,
18+
}
19+
}
20+
21+
pub fn success(mut self, success: bool) -> Self {
22+
self.success = Some(success);
23+
self
24+
}
25+
26+
pub fn error_message(mut self, error_message: &str) -> Self {
27+
self.error_message = Some(error_message.to_owned());
28+
self
29+
}
30+
31+
pub fn email(mut self, email: &str) -> Self {
32+
self.email = Some(email.to_owned());
33+
self
1134
}
1235
}
1336

pgml-dashboard/src/components/cards/newsletter_subscribe/newsletter_subscribe.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,17 @@ div[data-controller="cards-newsletter-subscribe"] {
99
background-image: url("/dashboard/static/images/newsletter_subscribe_background_mobile.png");
1010
background-color: #{$pink};
1111
}
12+
13+
.message {
14+
display: none;
15+
16+
&.success, &.error {
17+
display: block;
18+
}
19+
20+
bottom: -3rem;
21+
@include media-breakpoint-up(xl) {
22+
left: 0px;
23+
}
24+
}
1225
}

pgml-dashboard/src/components/cards/newsletter_subscribe/newsletter_subscribe_controller.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,54 @@
1-
<div data-controller="cards-newsletter-subscribe">
2-
<div class="d-flex flex-column flex-lg-row gap-4 justify-content-center align-items-center newsletter-subscribe-container p-5 rounded-4">
3-
<div class="d-flex flex-column gap-4 text-center text-md-start" style="flex: 4">
4-
<h3>Subscribe to our newsletter. (It’s better than you think)</h3>
5-
<p>No spam. No sales pitches. Just product updates. Keep up with all our articles and news. Join our newsletter and stay up to date!</p>
6-
</div>
1+
<%
2+
use pgml_components::Component;
3+
4+
let success_class = match success {
5+
Some(true) => "success",
6+
Some(false) => "error",
7+
None => ""
8+
};
9+
10+
let message = match success {
11+
Some(true) => "Success".to_string(),
12+
Some(false) => error_message.unwrap_or("Something went wrong".to_string()),
13+
None => String::new()
14+
};
15+
16+
let error_icon = match success {
17+
Some(false) => Component::from(r#"<span class="material-symbols-outlined m-auto pe-2 text-error">warning</span>"#),
18+
_ => Component::from("")
19+
};
720

8-
<form action="/newsletter_subscribe" class="d-flex flex-column justify-content-center align-items-center gap-3 w-100" style="flex: 3" method="post" data-cards-newsletter-subscribe-target="form">
9-
<div class="input-group p-1 ps-3 subscribe-input">
10-
<input type="email" class="form-control border-0" placeholder="hootareyou@email.com" name="email" autocomplete="off">
11-
<!-- <button type="submit" class="btn btn-primary rounded-2 d-none d-md-block">Subscribe</button> -->
12-
<button type="button" class="btn btn-primary rounded-2 d-none d-md-block" data-action="cards-newsletter-subscribe#submitRequest">Subscribe</button>
21+
let email_placeholder = match &email {
22+
Some(email) => email.clone().to_string(),
23+
None => {
24+
let message = match success {
25+
Some(true) => "Add Another Email".to_string(),
26+
_ => "hootareyou@email.com".to_string()
27+
};
28+
message
29+
}
30+
};
31+
%>
32+
33+
<turbo-frame id="newsletter-subscribe-frame">
34+
<div data-controller="cards-newsletter-subscribe">
35+
<div class="d-flex flex-column flex-lg-row gap-5 justify-content-between align-items-center newsletter-subscribe-container p-5 rounded-4">
36+
<div class="d-flex flex-column gap-4 text-center text-md-start w-100">
37+
<h3>Subscribe to our newsletter.<br> (It’s better than you think)</h3>
38+
<p>No spam. No sales pitches. Just product updates. Keep up with all our articles and news. Join our newsletter and stay up to date!</p>
39+
</div>
40+
41+
<div class="d-flex flex-column justify-content-center align-items-xl-end align-items-center gap-3 w-100 position-relative" style="max-width: 27rem;">
42+
<form action="/newsletter_subscribe" class="d-flex flex-lg-row flex-column gap-3 w-100" method="post">
43+
<div class="input-group p-1 ps-3 subscribe-input">
44+
<input type="email" class="form-control border-0" placeholder="<%- email_placeholder %>" name="email" autocomplete="off" <% if email.is_some() {%>value="<%- email.unwrap() %><% } %>">
45+
<%+ error_icon %>
46+
<button type="submit" class="btn btn-primary rounded-2 d-none d-md-block">Subscribe</button>
47+
</div>
48+
<button type="submit" class="btn btn-primary rounded-2 d-md-none mx-auto">Subscribe</button>
49+
</form>
50+
<p class="message <%- success_class %> position-absolute body-small-text"><%- message %></p>
1351
</div>
14-
<button type="submit" class="btn btn-primary rounded-2 d-md-none" data-action="cards-newsletter-subscribe#submitRequest">Subscribe</button>
15-
</form>
52+
</div>
1653
</div>
17-
</div>
54+
</turbo-frame>

pgml-dashboard/src/components/loading/message/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use sailfish::TemplateOnce;
21
use pgml_components::component;
2+
use sailfish::TemplateOnce;
33

44
#[derive(TemplateOnce, Default)]
55
#[template(path = "loading/message/template.html")]

pgml-dashboard/src/components/pages/blog/landing_page/template.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use crate::components::sections::common_resources::{Cards, CommonResources};
55
use crate::components::pages::blog::blog_search::call::Call as BlogSearchCall;
66
use crate::components::cards::NewsletterSubscribe;
7-
8-
7+
use crate::utils::config::standalone_dashboard;
98

109
let cards = featured_cards.iter().map(|card| {
1110
ArticlePreview::new(card).featured().render_once().unwrap()
@@ -37,9 +36,12 @@ <h1>PostgresML <span class="text-gradient-blue">Blog</span></h1>
3736
<%+ BlogSearchCall::new() %>
3837
</div>
3938

39+
40+
<% if !standalone_dashboard() { %>
4041
<div class="mt-5 container">
4142
<%+ NewsletterSubscribe::new() %>
4243
</div>
44+
<% } %>
4345

4446
<div class="mt-5">
4547
<%+ CommonResources::new().show(Vec::from([Cards::Contribute, Cards::Docs, Cards::Community])) %>

pgml-dashboard/src/components/pages/careers/landing_page/template.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<%
22
use crate::components::sections::common_resources::{CommonResources, Cards};
33
use crate::components::sections::EmploymentBenefits;
4+
use crate::components::cards::NewsletterSubscribe;
5+
use crate::utils::config::standalone_dashboard;
46
%>
57

68
<div data-controller="pages-careers-landing-page" class="overflow-hidden tuck-under-navbar">
@@ -84,7 +86,15 @@ <h2>Working with us</h2>
8486
<%+ EmploymentBenefits::new() %>
8587
</div>
8688

87-
<%+ CommonResources::new().show(Vec::from([Cards::Contribute, Cards::Docs, Cards::Community])) %>
89+
<% if !standalone_dashboard() { %>
90+
<div class="mt-5 container">
91+
<%+ NewsletterSubscribe::new() %>
92+
</div>
93+
<% } %>
94+
95+
<div class="mt-5">
96+
<%+ CommonResources::new().show(Vec::from([Cards::Contribute, Cards::Docs, Cards::Community])) %>
97+
</div>
8898

8999
</div>
90100
</div>

0 commit comments

Comments
 (0)