Skip to content

Commit

Permalink
Merge pull request #3 from djkato/ups
Browse files Browse the repository at this point in the history
Ups
  • Loading branch information
djkato authored Nov 15, 2024
2 parents 55f4994 + 43d8401 commit 34670c3
Show file tree
Hide file tree
Showing 29 changed files with 37,208 additions and 302 deletions.
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## COMMON VARIABLES FOR ALL APPS
REQUIRED_SALEOR_VERSION="^3.13"
# only sets port, the host is always 0.0.0.0 (listens to everything). Set this to docker-compose service name
APP_API_BASE_URL="http://10.100.110.29:3000"
APP_IFRAME_BASE_URL="http://10.100.110.29:3000"
APP_API_BASE_URL="http://10.100.110.60:3000"
APP_IFRAME_BASE_URL="http://10.100.110.60:3000"
APL="File"
APL_URL="./temp/apl.json"
APL_URL="apl.json"
LOG_LEVEL="DEBUG"

## THESE VARIABLES ARE FOR SITEMAP-GENERATOR APP
Expand Down
70 changes: 61 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions apl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"http://localhost:8000/graphql/": {
"domain": "http://10.100.110.60:3000",
"token": "NhJa5QG3J4UGbXQSiYF9L7HySMCKqA",
"saleorApiUrl": "http://localhost:8000/graphql/",
"appId": "saleor-app-template-ui",
"jwks": null
}
}
18 changes: 2 additions & 16 deletions app-template-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,8 @@ envy = { workspace = true }
cynic = { workspace = true, features = ["http-surf"], optional = true }
surf = { workspace = true, optional = true }

[target.'cfg(target_family = "unix")'.dependencies]
saleor-app-sdk = { workspace = true, optional = true, features = [
"file_apl",
"recommended",
"bridge",
] }

[target.'cfg(target_family = "wasm")'.dependencies]
saleor-app-sdk = { workspace = true, optional = true, features = ["bridge"] }
saleor-app-sdk = { workspace = true, optional = true }

[build-dependencies]
cynic-codegen = { workspace = true, optional = true }
Expand Down Expand Up @@ -77,6 +70,7 @@ ssr = [
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"saleor-app-sdk/bridge",
]
hydrate = [
"leptos/hydrate",
Expand All @@ -87,14 +81,6 @@ hydrate = [
]


# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "saleor-app-template-ui"
Expand Down
74 changes: 71 additions & 3 deletions app-template-ui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use crate::error_template::{AppError, ErrorTemplate};
use crate::routes::extensions::order_to_pdf::Pdf;
use crate::routes::extensions::order_to_pdf::OrderToPdf;
use crate::routes::home::Home;
use leptos::*;
use leptos_dom::logging::{console_error, console_log};
use leptos_meta::*;
use leptos_router::*;
use saleor_app_sdk::bridge::action::PayloadRequestPermissions;
use saleor_app_sdk::bridge::event::Event;
use saleor_app_sdk::bridge::{dispatch_event, listen_to_events, AppBridge};
use saleor_app_sdk::manifest::AppPermission;

#[derive(Params, PartialEq)]
pub struct UrlAppParams {
Expand All @@ -12,7 +17,70 @@ pub struct UrlAppParams {

#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
let (bridge_read, bridge_set) = create_signal::<Option<AppBridge>>(None);

create_effect(move |_| match AppBridge::new(true) {
Ok(bridge) => bridge_set(Some(bridge)),
Err(e) => console_error(&format!("{:?}", e)),
});

create_effect(move |_| {
if let Err(e) = dispatch_event(saleor_app_sdk::bridge::action::Action::RequestPermissions(
PayloadRequestPermissions {
permissions: vec![AppPermission::ManageOrders, AppPermission::ManageProducts],
redirect_path: None,
},
)) {
console_error(&format!("{:?}", e));
};
});

create_effect(move |_| {
listen_to_events(move |event_res| match event_res {
Ok(event) => match event {
Event::Handshake(payload) => {
if let Some(mut bridge) = bridge_read.get_untracked() {
bridge.state.token = Some(payload.token);
bridge.state.dashboard_version = payload.dashboard_version;
bridge.state.saleor_version = payload.saleor_version;
bridge_set(Some(bridge))
}
}
Event::Response(_) => {
// console_log(&format!("front::App: {:?}", payload.ok));
if let Some(mut bridge) = bridge_read.get_untracked() {
bridge.state.ready = true;
bridge_set(Some(bridge))
}
}
Event::Redirect(payload) => {
console_log(&payload.path);
}
Event::Theme(payload) => {
if let Some(mut bridge) = bridge_read.get_untracked() {
bridge.state.theme = payload.theme;
bridge_set(Some(bridge))
}
}
Event::LocaleChanged(payload) => {
if let Some(mut bridge) = bridge_read.get_untracked() {
bridge.state.locale = payload.locale;
bridge_set(Some(bridge))
}
}
Event::TokenRefreshed(payload) => {
if let Some(mut bridge) = bridge_read.get_untracked() {
bridge.state.token = Some(payload.token);
bridge_set(Some(bridge))
}
}
},
Err(e) => {
console_error(&format!("front::App: {:?}", e));
}
})
});

provide_meta_context();
view! {
<Stylesheet id="leptos" href="/pkg/saleor-app-template-ui.css" />
Expand All @@ -29,7 +97,7 @@ pub fn App() -> impl IntoView {
<main class="p-4 md:p-8 md:px-16">
<Routes>
<Route path="/" view=Home />
<Route path="/extensions/order_to_pdf" view=Pdf />
<Route path="/extensions/order_to_pdf" view=move || view!{<OrderToPdf bridge=bridge_read />}/>
</Routes>
</main>
</Router>
Expand Down
16 changes: 10 additions & 6 deletions app-template-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ async fn main() -> Result<(), std::io::Error> {
let saleor_app = SaleorApp::new(&config).unwrap();

let app_manifest = AppManifestBuilder::new(&config, cargo_info!())
.add_permissions(vec![AppPermission::ManageProducts, AppPermission::ManageOrders, AppPermission::ManageProductTypesAndAttributes])
.add_permissions(vec![
AppPermission::ManageProducts,
AppPermission::ManageOrders,
AppPermission::ManageProductTypesAndAttributes,
])
.add_extension(
AppExtensionBuilder::new()
.set_url("/extensions/order_to_pdf")
Expand All @@ -69,7 +73,8 @@ async fn main() -> Result<(), std::io::Error> {
.set_target(AppExtensionTarget::Popup)
.build(),
)
.build();
.build()
.expect("Manifest has invalid parameters");

let app_state = AppState {
manifest: app_manifest,
Expand All @@ -89,13 +94,12 @@ async fn main() -> Result<(), std::io::Error> {
.fallback(file_and_error_handler)
.route(
"/api/webhooks",
post(webhooks)
// .route_layer(middleware::from_fn(webhook_signature_verifier)),
post(webhooks)//.route_layer(middleware::from_fn(webhook_signature_verifier)),
)
.route(
"/api/register",
post(register)
// .route_layer(middleware::from_fn(webhook_signature_verifier)),
post(register)//.route_layer(middleware::from_fn(webhook_signature_verifier)),

)
.route("/api/manifest", get(manifest))
.with_state(app_state.clone());
Expand Down
Loading

0 comments on commit 34670c3

Please sign in to comment.