Skip to content

Commit

Permalink
ajust all userInfo, fix update user info
Browse files Browse the repository at this point in the history
  • Loading branch information
AldemirLucas committed Dec 18, 2023
1 parent a25aa99 commit 5084e6e
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 213 deletions.
4 changes: 2 additions & 2 deletions next/components/molecules/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function MenuDrawerUser({ isOpen, onClose}) {
letterSpacing="0.3px"
onClick={() => {
onClose()
router.push({pathname: "/user/dev", query: elm.value})}
router.push({pathname: `/user/${userData.username}`, query: elm.value})}
}
>{elm.name}</Link>
)
Expand Down Expand Up @@ -425,7 +425,7 @@ function MenuUser ({ userData, onOpen, onClose }) {
gap="8px"
padding="16px"
_hover={{ backgroundColor: "transparent", opacity: "0.6" }}
onClick={() => window.open("/user/dev", "_self")}
onClick={() => window.open(`/user/${userData.username}`, "_self")}
>
<SettingsIcon fill="#D0D0D0" width="16px" height="16px"/>
<Text
Expand Down
3 changes: 2 additions & 1 deletion next/components/organisms/BdmTablePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export default function BdmTablePage({ id }) {
alt = "usuário ckan"
}
if(ref.website) {
href = `https://${ref.website}`
const website = ref.website.replace(/(https?:)\/\//gim, "")
href = `https://${website}`
alt = "website pessoal"
}

Expand Down
4 changes: 0 additions & 4 deletions next/pages/api/stripe/createCustomer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import axios from "axios";
import cookies from "js-cookie";
import { refreshToken } from "../user";
import { getUserDataJson } from "../../../utils";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

let userData = getUserDataJson()

export default async function createCustomer() {
const refresh = await refreshToken()
if(refresh?.errors.length > 0) return {error: "failed to revalidate the token"}

let token = cookies.get("token") || ""

try {
Expand Down
4 changes: 0 additions & 4 deletions next/pages/api/stripe/createSubscription.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import axios from "axios";
import cookies from "js-cookie";
import { refreshToken } from "../user";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

export default async function createSubscription( priceId ) {
const refresh = await refreshToken()
if(refresh?.errors.length > 0) return {error: "failed to revalidate the token"}

let token = cookies.get("token") || ""

try {
Expand Down
11 changes: 2 additions & 9 deletions next/pages/api/stripe/removeSubscription.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import axios from "axios";
import cookies from "js-cookie";
import { refreshToken } from "../user";
import { getUserDataJson } from "../../../utils";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

let userData = getUserDataJson()

export default async function removeSubscription() {
const refresh = await refreshToken()
if(refresh?.errors.length > 0) return {error: "failed to revalidate the token"}

export default async function removeSubscription({ id }) {
let token = cookies.get("token") || ""

try {
Expand All @@ -23,7 +16,7 @@ export default async function removeSubscription() {
data: {
query: `
mutation {
deleteStripeSubscription (subscriptionId: 74)
deleteStripeSubscription (subscriptionId: ${id})
{
errors
}
Expand Down
4 changes: 3 additions & 1 deletion next/pages/api/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import getUser from "./getUser";
import getAllUsers from "./getAllUsers";
import getFullUser from "./getFullUser";
import updateProfile from "./updateProfile";
import updateUser from "./updateUser";

export {
getToken,
Expand All @@ -15,5 +16,6 @@ export {
getUser,
getAllUsers,
getFullUser,
updateProfile
updateProfile,
updateUser
}
44 changes: 44 additions & 0 deletions next/pages/api/user/updateUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from "axios";
import cookies from "js-cookie";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

export default async function updateUser({
id,
email,
username,
}) {
let token = cookies.get("token") || ""

try {
const res = await axios({
url: API_URL,
method: "POST",
headers: {
Authorization: `Bearer ${token}`
},
data: {
query: `
mutation {
CreateUpdateAccount (input:
{
id: "${id}"
email: "${email}"
username: "${username}"
}
)
{
errors {
field,
messages
}
}
}`
}
})
const data = res.data.data.CreateUpdateAccount
return data
} catch (error) {
console.error(error)
}
}
2 changes: 1 addition & 1 deletion next/pages/quem-somos.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const TeamBox = ({
let href = ""

if(ref.website) {
const website = ref.website.replace(/(https:)\/\//gim, "")
const website = ref.website.replace(/(https?:)\/\//gim, "")
href = `https://${website}`
}
if(ref.email) href = `mailto:${ref.email}`
Expand Down
Loading

0 comments on commit 5084e6e

Please sign in to comment.