Skip to content

Commit

Permalink
Merge pull request #732 from basedosdados/feat/user-page
Browse files Browse the repository at this point in the history
Feat/user page
  • Loading branch information
AldemirLucas authored Dec 18, 2023
2 parents 97ca211 + 5084e6e commit 3519fa9
Show file tree
Hide file tree
Showing 18 changed files with 603 additions and 231 deletions.
6 changes: 3 additions & 3 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 Expand Up @@ -764,7 +764,7 @@ function DesktopLinks({ links, position = false, path, userTemplate = false }) {
<HStack spacing={8} display={{ base: "none", lg: "flex" }}>
{userData ? (
<HStack spacing="20px">
{userData?.currentSubscriptionStatus[0] !== "active" &&
{userData?.proSubscriptionStatus !== "active" &&
<RoundedButton
display={isMobileMod() ? "none" : "flex"}
backgroundColor="#FFF"
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
15 changes: 12 additions & 3 deletions next/components/organisms/PaymentSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import {
useElements,
useStripe,
} from "@stripe/react-stripe-js";
import cookies from "js-cookie";
import Button from "../atoms/RoundedButton";

import {
getUser
} from "../../pages/api/user"

import {
getPrices,
createCustomer,
Expand All @@ -21,7 +26,7 @@ import {

const stripePromise = loadStripe(process.env.NEXT_PUBLIC_KEY_STRIPE)

const PaymentForm = () => {
const PaymentForm = ({ userData }) => {
const stripe = useStripe()
const elements = useElements()

Expand All @@ -35,6 +40,10 @@ const PaymentForm = () => {
// return_url: "/"
// }
})

const user = await getUser(userData?.email)
cookies.set('userBD', JSON.stringify(user))
window.open(`/user/${user?.username}?plans_and_payment`, "_self")
}

return (
Expand All @@ -51,7 +60,7 @@ const PaymentForm = () => {
)
}

export default function PaymentSystem() {
export default function PaymentSystem({ userData }) {
const [clientSecret, setClientSecret] = useState("")

const appearance = {
Expand Down Expand Up @@ -90,7 +99,7 @@ export default function PaymentSystem() {
{clientSecret && (
<Elements options={options} stripe={stripePromise}>
<AddressElement options={{mode:'billing'}}/>
<PaymentForm />
<PaymentForm userData={userData}/>
</Elements>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion next/middlewares/authUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function authUser(context, destiny) {
cookies.remove('token', { path: '/' })

res.setHeader('Set-Cookie', [
`user=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`,
`userBD=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`,
`token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`
])

Expand Down
2 changes: 0 additions & 2 deletions next/pages/api/stripe/createCustomer.js
Original file line number Diff line number Diff line change
@@ -1,14 +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() {
refreshToken()
let token = cookies.get("token") || ""

try {
Expand Down
2 changes: 0 additions & 2 deletions next/pages/api/stripe/createSubscription.js
Original file line number Diff line number Diff line change
@@ -1,11 +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 ) {
refreshToken()
let token = cookies.get("token") || ""

try {
Expand Down
9 changes: 2 additions & 7 deletions next/pages/api/stripe/removeSubscription.js
Original file line number Diff line number Diff line change
@@ -1,14 +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() {
refreshToken()
export default async function removeSubscription({ id }) {
let token = cookies.get("token") || ""

try {
Expand All @@ -21,7 +16,7 @@ export default async function removeSubscription() {
data: {
query: `
mutation {
deleteStripeSubscription (subscriptionId: 74)
deleteStripeSubscription (subscriptionId: ${id})
{
errors
}
Expand Down
45 changes: 45 additions & 0 deletions next/pages/api/user/getFullUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from "axios";

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

export default async function getFullUser(email) {
try {
const res = await axios({
url: API_URL,
method: "POST",
data: {
query: `
query {
allAccount (email : "${email}"){
edges {
node {
id
isAdmin
isActive
isEmailVisible
picture
username
firstName
lastName
email
website
github
twitter
linkedin
proSubscription
proSubscriptionRole
proSubscriptionSlots
proSubscriptionStatus
}
}
}
}
`
}
})
const data = res.data?.data?.allAccount?.edges[0]?.node
return data
} catch (error) {
console.error(error)
}
}
4 changes: 2 additions & 2 deletions next/pages/api/user/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export default async function getUser(email) {
firstName
lastName
email
currentSubscription
currentSubscriptionStatus
proSubscription
proSubscriptionStatus
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion next/pages/api/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import validateToken from "./validateToken";
import registerAccount from "./registerAccount";
import getUser from "./getUser";
import getAllUsers from "./getAllUsers";
import getFullUser from "./getFullUser";
import updateProfile from "./updateProfile";
import updateUser from "./updateUser";

export {
getToken,
refreshToken,
validateToken,
registerAccount,
getUser,
getAllUsers
getAllUsers,
getFullUser,
updateProfile,
updateUser
}
3 changes: 1 addition & 2 deletions next/pages/api/user/refreshToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export default async function refreshToken() {
if(res.data.errors.length > 0) {
cookies.remove('userBD', { path: '/' })
cookies.remove('token', { path: '/' })

return window.open("/user/login", "_self")
return res.data
}
cookies.set('token', data?.refreshToken?.token)
return data
Expand Down
56 changes: 56 additions & 0 deletions next/pages/api/user/updateProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 updateProfile({
id,
firstName,
lastName = "",
isEmailVisible = false,
// picture,
website = "",
github = "",
twitter = "",
linkedin = ""
}) {
let token = cookies.get("token") || ""
// picture: "${picture}"

try {
const res = await axios({
url: API_URL,
method: "POST",
headers: {
Authorization: `Bearer ${token}`
},
data: {
query: `
mutation {
CreateUpdateAccount (input:
{
id: "${id}"
firstName: "${firstName}"
lastName: "${lastName}"
isEmailVisible: ${isEmailVisible}
website: "${website}"
github: "${github}"
twitter: "${twitter}"
linkedin: "${linkedin}"
}
)
{
errors {
field,
messages
}
}
}`
}
})
const data = res.data.data.CreateUpdateAccount
return data
} catch (error) {
console.error(error)
}
}
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)
}
}
8 changes: 4 additions & 4 deletions next/pages/precos.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@ export default function Price() {
{name: "Dezenas de bases de alta frequência atualizadas"},
]}
button={{
text: `${userData?.currentSubscription[0] === "BD Pro Completo" ? "Plano atual" : "Iniciar teste grátis"}`,
onClick: userData?.currentSubscription[0] === "BD Pro Completo" ? () => {} : () => setPlan({plan: "BD Pro"}),
text: `${userData?.proSubscription === "bd_pro" ? "Plano atual" : "Iniciar teste grátis"}`,
onClick: userData?.proSubscription === "bd_pro" ? () => {} : () => setPlan({plan: "BD Pro"}),
styles:
userData?.currentSubscription[0] === "BD Pro Completo" && {
userData?.proSubscription === "bd_pro" && {
color: "#252A32",
backgroundColor: "#FFF",
boxShadow: "none",
Expand All @@ -480,7 +480,7 @@ export default function Price() {

<CardPrice
colorBanner="#252A32"
title="BD Empresas"
title="BD Pro Empresas"
badge="Beta"
subTitle={<BodyText>Para sua empresa ganhar tempo<br/> e qualidade em decisões</BodyText>}
personConfig={{
Expand Down
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 3519fa9

Please sign in to comment.