From 2ea78cdebdb19c90d9843dd785b389c5a1aed7fb Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Wed, 12 Jun 2024 16:25:33 +0500 Subject: [PATCH 1/4] remove react router --- package.json | 1 - static/js/src/advantage/credentials/app.tsx | 7 +- .../src/advantage/credentials/utils/utils.ts | 15 -- templates/credentials/shop/index.html | 250 +++++++++--------- webapp/shop/cred/views.py | 1 + yarn.lock | 20 -- 6 files changed, 132 insertions(+), 162 deletions(-) delete mode 100644 static/js/src/advantage/credentials/utils/utils.ts diff --git a/package.json b/package.json index 4dc565e4e16..15e8c892548 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,6 @@ "react-dom": "17.0.2", "react-google-recaptcha": "2.1.0", "react-query": "3.34.7", - "react-router-dom": "^6.8.0", "react-useportal": "1.0.16", "sass": "1.45.2", "smartquotes": "2.3.2", diff --git a/static/js/src/advantage/credentials/app.tsx b/static/js/src/advantage/credentials/app.tsx index 9eef87ed2ce..ef704f405cc 100644 --- a/static/js/src/advantage/credentials/app.tsx +++ b/static/js/src/advantage/credentials/app.tsx @@ -4,7 +4,6 @@ import * as Sentry from "@sentry/react"; import { QueryClient, QueryClientProvider } from "react-query"; import { Integrations } from "@sentry/tracing"; import { ReactQueryDevtools } from "react-query/devtools"; -import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import CredManage from "./components/CredManage"; const oneHour = 1000 * 60 * 60; @@ -34,11 +33,7 @@ function App() { return ( - - - } /> - - + diff --git a/static/js/src/advantage/credentials/utils/utils.ts b/static/js/src/advantage/credentials/utils/utils.ts deleted file mode 100644 index f755d57c1e9..00000000000 --- a/static/js/src/advantage/credentials/utils/utils.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { UserSubscriptionMarketplace } from "advantage/api/enum"; - -export type Product = { - longId?: string; - name: string; - price?: { - value: number; - currency: string; - original?: number; - }; - id: string; - marketplace?: UserSubscriptionMarketplace; - metadata: Array<{ key: string; value: string }>; - displayName?: string; -}; diff --git a/templates/credentials/shop/index.html b/templates/credentials/shop/index.html index 59b686eea00..c753b1d50e9 100644 --- a/templates/credentials/shop/index.html +++ b/templates/credentials/shop/index.html @@ -8,133 +8,141 @@ {% endblock meta_description %} {% block content %} -
-
-
-

Select an exam to purchase

-
-
+ {% if not is_manage %} + +
+
+

Select an exam to purchase

+
+
+ {% for exam in exams %} + {% set metadata_length = exam.metadata|length %} + {% set is_disabled = metadata_length == 1 %} + {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} +
+
+ +
+
+ {% endfor %} +
+ + {% for exam in exams %} {% set metadata_length = exam.metadata|length %} {% set is_disabled = metadata_length == 1 %} {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} -
+
-
{% endfor %}
- - {% for exam in exams %} - {% set metadata_length = exam.metadata|length %} - {% set is_disabled = metadata_length == 1 %} - {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} -
-
- - -

{{ exam.metadata[0].value }}

-
- -
- {% if is_disabled %} - Coming Soon! +
+
+
Your Order
+
+
+ {% set exam = exams[exam_index] %} + {% set is_discounted = True if exam.metadata|length > 1 and exam.metadata[1].discountPrice else False %} +
+

{{ exam.displayName }}

+
+
+

+ + {% if is_discounted %} + {{ exam.metadata[1].currency }}{{ exam.metadata[1].discountPrice }} {% else %} - Price: - {% if is_discounted %}{{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }}{% endif %} - {{ exam.metadata[1].currency }} - {% if is_discounted %} - {{ exam.metadata[1].discountPrice }} - {% else %} - {{ exam.metadata[1].originalPrice }} - {% endif %} - + {{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }} {% endif %} -

-
+ +

+
+
+
- {% endfor %} -
- -
-
-
Your Order
-
-
- {% set exam = exams[exam_index] %} - {% set is_discounted = True if exam.metadata|length > 1 and exam.metadata[1].discountPrice else False %} -
-

{{ exam.displayName }}

-
-
-

- - {% if is_discounted %} - {{ exam.metadata[1].currency }}{{ exam.metadata[1].discountPrice }} - {% else %} - {{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }} - {% endif %} - -

-
-
- -
-
-
- + + + {% else %} +
+ + {% endif %} {% endblock %} diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index 1abd820a9a1..ff91c002d80 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -871,6 +871,7 @@ def cred_shop(**kwargs): "credentials/shop/index.html", exams=exams, exam_index=0, + is_manage="manage" in flask.request.full_path, ) diff --git a/yarn.lock b/yarn.lock index c835ce1991e..f51dc9a4d7a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1393,11 +1393,6 @@ redux-thunk "^2.4.1" reselect "^4.1.5" -"@remix-run/router@1.3.1": - version "1.3.1" - resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.3.1.tgz#3bb0b6ddc0a276e8dc1138d08f63035e4e23e8bf" - integrity sha512-+eun1Wtf72RNRSqgU7qM2AMX/oHp+dnx7BHk1qhK5ZHzdHTUU4LA1mGG1vT+jMc8sbhG3orvsfOmryjzx2PzQw== - "@sentry/browser@6.11.0": version "6.11.0" resolved "https://registry.npmjs.org/@sentry/browser/-/browser-6.11.0.tgz" @@ -6631,21 +6626,6 @@ react-query@3.34.7: broadcast-channel "^3.4.1" match-sorter "^6.0.2" -react-router-dom@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.8.0.tgz#5e5f4c4b15fdec3965d2ad9d7460d0c61971e744" - integrity sha512-hQouduSTywGJndE86CXJ2h7YEy4HYC6C/uh19etM+79FfQ6cFFFHnHyDlzO4Pq0eBUI96E4qVE5yUjA00yJZGQ== - dependencies: - "@remix-run/router" "1.3.1" - react-router "6.8.0" - -react-router@6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.8.0.tgz#dd61fd1ec44daa2cceaef8e6baa00f99a01a650f" - integrity sha512-760bk7y3QwabduExtudhWbd88IBbuD1YfwzpuDUAlJUJ7laIIcqhMvdhSVh1Fur1PE8cGl84L0dxhR3/gvHF7A== - dependencies: - "@remix-run/router" "1.3.1" - react-shallow-renderer@^16.13.1: version "16.14.1" resolved "https://registry.npmjs.org/react-shallow-renderer/-/react-shallow-renderer-16.14.1.tgz" From ac631a5329c37e86c5b0b6cc61437ce56808fe6d Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Wed, 12 Jun 2024 16:30:04 +0500 Subject: [PATCH 2/4] format app.tsx --- static/js/src/advantage/credentials/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/src/advantage/credentials/app.tsx b/static/js/src/advantage/credentials/app.tsx index ef704f405cc..9d0c0355069 100644 --- a/static/js/src/advantage/credentials/app.tsx +++ b/static/js/src/advantage/credentials/app.tsx @@ -33,7 +33,7 @@ function App() { return ( - + From f7f43ea33571aceabd35508326290ea2e7d0ad2b Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Wed, 12 Jun 2024 18:54:53 +0500 Subject: [PATCH 3/4] create separate view for credentials/shop/manage --- templates/credentials/shop/index.html | 242 ++++++++++++------------- templates/credentials/shop/manage.html | 15 ++ webapp/app.py | 4 + webapp/shop/cred/views.py | 8 + 4 files changed, 143 insertions(+), 126 deletions(-) create mode 100644 templates/credentials/shop/manage.html diff --git a/templates/credentials/shop/index.html b/templates/credentials/shop/index.html index c753b1d50e9..3845ea719d5 100644 --- a/templates/credentials/shop/index.html +++ b/templates/credentials/shop/index.html @@ -8,141 +8,133 @@ {% endblock meta_description %} {% block content %} - {% if not is_manage %} -
-
-
-

Select an exam to purchase

-
-
- {% for exam in exams %} - {% set metadata_length = exam.metadata|length %} - {% set is_disabled = metadata_length == 1 %} - {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} -
-
- -
-
- {% endfor %} -
- - + +
+
+

Select an exam to purchase

+
+
{% for exam in exams %} {% set metadata_length = exam.metadata|length %} {% set is_disabled = metadata_length == 1 %} {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} -
+
-
{% endfor %}
-
-
-
Your Order
-
-
- {% set exam = exams[exam_index] %} - {% set is_discounted = True if exam.metadata|length > 1 and exam.metadata[1].discountPrice else False %} -
-

{{ exam.displayName }}

-
-
-

- - {% if is_discounted %} - {{ exam.metadata[1].currency }}{{ exam.metadata[1].discountPrice }} + + {% for exam in exams %} + {% set metadata_length = exam.metadata|length %} + {% set is_disabled = metadata_length == 1 %} + {% set is_discounted = True if metadata_length > 1 and exam.metadata[1].discountPrice else False %} +

+
+ + +

{{ exam.metadata[0].value }}

+
+ +
+ {% if is_disabled %} + Coming Soon! {% else %} - {{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }} + Price: + {% if is_discounted %}{{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }}{% endif %} + {{ exam.metadata[1].currency }} + {% if is_discounted %} + {{ exam.metadata[1].discountPrice }} + {% else %} + {{ exam.metadata[1].originalPrice }} + {% endif %} + {% endif %} - -

-
-
- + +
-
- - {% else %} -
- - {% endif %} + {% endfor %} +
+ +
+
+
Your Order
+
+
+ {% set exam = exams[exam_index] %} + {% set is_discounted = True if exam.metadata|length > 1 and exam.metadata[1].discountPrice else False %} +
+

{{ exam.displayName }}

+
+
+

+ + {% if is_discounted %} + {{ exam.metadata[1].currency }}{{ exam.metadata[1].discountPrice }} + {% else %} + {{ exam.metadata[1].currency }}{{ exam.metadata[1].originalPrice }} + {% endif %} + +

+
+
+ +
+
+
+ {% endblock %} diff --git a/templates/credentials/shop/manage.html b/templates/credentials/shop/manage.html new file mode 100644 index 00000000000..696d6c7d9c6 --- /dev/null +++ b/templates/credentials/shop/manage.html @@ -0,0 +1,15 @@ +{% extends "credentials/base_cred.html" %} + +{% block title %}Canonical Certification{% endblock %} + +{% block meta_description %} + The Canonical Ubuntu Essentials exams certify knowledge and verify skills in general Linux, + Ubuntu Desktop, and Ubuntu Server topics. +{% endblock meta_description %} + +{% block content %} +
+ +{% endblock %} diff --git a/webapp/app.py b/webapp/app.py index fd0647db9e4..b245cdbf947 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -74,6 +74,7 @@ cred_schedule, cred_self_study, cred_shop, + cred_manage_shop, cred_shop_thank_you, cred_shop_webhook_responses, cred_shop_keys, @@ -883,6 +884,9 @@ def takeovers_index(): methods=["GET", "POST"], ) app.add_url_rule("/credentials/shop/", view_func=cred_shop) +app.add_url_rule( + "/credentials/shop/manage/", view_func=cred_manage_shop, methods=["GET"] +) app.add_url_rule("/credentials/shop/

", view_func=cred_shop) app.add_url_rule("/credentials/shop/keys", view_func=cred_shop_keys) app.add_url_rule( diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index ff91c002d80..edff6adfe95 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -875,6 +875,14 @@ def cred_shop(**kwargs): ) +@shop_decorator(area="cube", permission="user", response="html") +@canonical_staff() +def cred_manage_shop(**kwargs): + return flask.render_template( + "credentials/shop/manage.html", + ) + + @shop_decorator(area="cube", permission="user", response="html") @canonical_staff() def cred_shop_thank_you(**kwargs): From bef59da455bb5388351a8be17c04b534b5dd2ee5 Mon Sep 17 00:00:00 2001 From: usamabinnadeem-10 Date: Wed, 12 Jun 2024 19:12:31 +0500 Subject: [PATCH 4/4] remove unused template variable --- webapp/shop/cred/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/webapp/shop/cred/views.py b/webapp/shop/cred/views.py index edff6adfe95..e7abe777d56 100644 --- a/webapp/shop/cred/views.py +++ b/webapp/shop/cred/views.py @@ -871,7 +871,6 @@ def cred_shop(**kwargs): "credentials/shop/index.html", exams=exams, exam_index=0, - is_manage="manage" in flask.request.full_path, )