From e2bb8d89a28f1d3ba572ad498d6c11628981651c Mon Sep 17 00:00:00 2001
From: HobertJ <13521079@std.stei.itb.ac.id>
Date: Fri, 17 Nov 2023 11:29:49 +0700
Subject: [PATCH] feat: add subscribe to premium

---
 src/app/components/common/profile.php         | 20 +++++++++++--
 .../subscription/post_subscription.php        | 11 ++++++-
 src/public/styles/globals.css                 | 29 +++++++++++++++++--
 3 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/src/app/components/common/profile.php b/src/app/components/common/profile.php
index b8d496d..72977d6 100644
--- a/src/app/components/common/profile.php
+++ b/src/app/components/common/profile.php
@@ -10,6 +10,7 @@
         </div>
         <div class="profile-menu">
             <div class="item b3" id="menu-profile">Profile</div>
+            <button class="item b3" id="subscribe">Subscribe</button>
             <button class="item b3" id="logout">Log out</button>
         </div>
         <div class="edit-profile-back">
@@ -35,11 +36,26 @@
         e.preventDefault();
         const xhr = new XMLHttpRequest();
         xhr.open("POST", "/public/logout");
-        xhr.send()
+        xhr.send();
         xhr.onreadystatechange = function() {
             if (this.readyState === 4 && this.status === 200) {
-                window.location.replace("/public/login")
+                window.location.replace("/public/login");
             }
         }
     })
+
+    const subscribeBtn = document.getElementById("subscribe");
+    subscribeBtn.addEventListener("click", (e) => {
+        e.preventDefault();
+        const xhr = new XMLHttpRequest();
+        xhr.open("POST", "/public/subscribe", true);
+        xhr.send();
+        xhr.onreadystatechange = function() {
+            if (this.readyState === 4 && this.status === 201) {
+                alert("Berhasil Subscribe!, logout dan login kembali untuk masuk ke halaman premium.")
+                window.location.replace("http://localhost:5173");
+            }
+        }
+    })
+
 </script>
\ No newline at end of file
diff --git a/src/app/controllers/subscription/post_subscription.php b/src/app/controllers/subscription/post_subscription.php
index 77c3321..6618857 100644
--- a/src/app/controllers/subscription/post_subscription.php
+++ b/src/app/controllers/subscription/post_subscription.php
@@ -3,13 +3,22 @@
 class PostSubscribeController
 {
   public function call() {
+
+    session_start();
+
+    if (isset($_SESSION["user_id"])){
+      $user_id = $_SESSION["user_id"];
+    }else{
+      return;
+    }
+
     $xml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://services.soapserver/">
               <soap:Header>
                 <tns:apiKey>ularmelingkardiataspagar</tns:apiKey>
               </soap:Header>
               <soap:Body>
                 <tns:addSubscription>
-                  <idUser>8</idUser>
+                  <idUser>'.$user_id.'</idUser>
                 </tns:addSubscription>
               </soap:Body>
             </soap:Envelope>';
diff --git a/src/public/styles/globals.css b/src/public/styles/globals.css
index cebf275..0f6197c 100644
--- a/src/public/styles/globals.css
+++ b/src/public/styles/globals.css
@@ -416,11 +416,36 @@ aside .sidebar-item {
   align-items: start;
   z-index: 99;
   cursor: pointer;
-  width: 7vw;
+  width: 6vw;
 }
 
 #logout {
-  color: red;
+  color: var(--PINK-1);
+  text-align: center;
+  border-radius: 5px;
+  width: 85px;
+  background-color: var(--WHITE);
+  font-style: bold;
+}
+
+#logout:hover{
+  font-weight: 600;
+  background-color: var(--GRAY-100);
+}
+
+#subscribe {
+  color: var(--WHITE);
+  background-color: var(--PINK-1);
+  border-radius: 5px;
+  width: 85px;
+  text-align: center;
+  font-style: bold;
+}
+
+#subscribe:hover{
+  background-color: var(--GRAY-100);
+  color: var(--PINK-1);
+  font-weight: 600;
 }
 
 .edit-profile-back {
-- 
GitLab