Skip to content

Commit

Permalink
fix: dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
Angga Maulana authored and Angga Maulana committed Mar 26, 2023
1 parent 90774fb commit 4a44030
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 177 deletions.
47 changes: 0 additions & 47 deletions components/Molecules/CustomNode.js

This file was deleted.

12 changes: 0 additions & 12 deletions components/Molecules/Molecules.module.css

This file was deleted.

101 changes: 101 additions & 0 deletions components/Organizms/OrgChart/OrgChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, { useEffect, memo } from 'react'
import { Tree, TreeNode } from "react-organizational-chart";
import { useDispatch, useSelector } from 'react-redux';
import { ProfileActions } from 'store/redux/profileReducer';

const OrgChart = () => {
const dispatch = useDispatch();
const { tree } = useSelector(state => state.profileReducer)
const color = {
silver: "#c0c0c0",
gold: "#d4af37",
diamond: "#61e2ff",
}

const renderColor = (param) => {
const paket = param?.split(' ')[1].toLowerCase()

switch(paket){
case "gold":{
return color.gold;
}
case "silver":{
return color.silver
}
case "diamond":{
return color.diamond
}
default :
return "";
}
}

useEffect(()=>{
dispatch(ProfileActions.doGetTreeRequest())
},[])

const RenderNode = () => {
return tree?.data?.downlines?.map((item,i) => (
<>
<TreeNode key={i} label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5 justify-center" style={{backgroundColor: renderColor(item?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{item?.user?.name?.length > 0 && item?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{item?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
{item?.user?.downlines?.map((x,y) => (
<>
<TreeNode key={y} label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5" style={{backgroundColor: renderColor(x?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{x?.user?.name?.length > 0 && x?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{x?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
{x?.user?.downlines?.map((u,v) => (
<>
<TreeNode label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5" style={{backgroundColor: renderColor(u?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{u?.user?.name?.length > 0 && u?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{u?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
} />
</>
))}
</TreeNode>
</>
))}
</TreeNode>
</>
))
}
return (
<Tree
lineWidth={"2px"}
lineColor={"black"}
lineHeight={"40px"}
nodePadding={"5px"}
lineBorderRadius={"10px"}
label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5 jusify-center" style={{backgroundColor: renderColor(tree?.data?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{tree?.data?.name}</p>
<p className="font-italic text-sm text-white">{tree?.data?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
<RenderNode />
</Tree>
)
}

export default memo(OrgChart)
100 changes: 4 additions & 96 deletions pages/member/genealogy/diagram.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,9 @@
import React from 'react'
import Member from 'layouts/Member';
import React, { useEffect } from 'react'
import { Tree, TreeNode } from "react-organizational-chart";
import { useDispatch, useSelector } from 'react-redux';
import { ProfileActions } from 'store/redux/profileReducer';

import dynamic from "next/dynamic";
const Organizational = dynamic(() => import("../../../components/Organizms/OrgChart/OrgChart"),{ssr: false})
export default function Diagram() {
const dispatch = useDispatch();
const { tree } = useSelector(state => state.profileReducer)
const color = {
silver: "#c0c0c0",
gold: "#d4af37",
diamond: "#61e2ff",
}

const renderColor = (param) => {
const paket = param?.split(' ')[1].toLowerCase()
const pakets = param?.toLowerCase().includes("gold")
console.log("PAKET",paket)

switch(paket){
case "gold":{
return color.gold;
}
case "silver":{
return color.silver
}
case "diamond":{
return color.diamond
}
default :
return "";
}
}

useEffect(()=>{
dispatch(ProfileActions.doGetTreeRequest())
},[])

const RenderNode = () => {
return tree?.data?.downlines?.map((item,i) => (
<>
<TreeNode key={i} label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5 justify-center" style={{backgroundColor: renderColor(item?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{item?.user?.name?.length > 0 && item?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{item?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
{item?.user?.downlines?.map((x,y) => (
<>
<TreeNode key={y} label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5" style={{backgroundColor: renderColor(x?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{x?.user?.name?.length > 0 && x?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{x?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
{x?.user?.downlines?.map((u,v) => (
<>
<TreeNode label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5" style={{backgroundColor: renderColor(u?.user?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{u?.user?.name?.length > 0 && u?.user?.name?.substring(0, 7)+' ...'}</p>
<p className="font-italic text-sm text-white">{u?.user?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
} />
</>
))}
</TreeNode>
</>
))}
</TreeNode>
</>
))
}
return (
<div className="flex flex-wrap">
<div className="overflow-x-scroll w-full lg:w-12/12 px-4">
Expand All @@ -96,23 +20,7 @@ export default function Diagram() {
</div>
</div>
<div className="overflow-x-scroll flex px-4 lg:px-10 py-10 pt-0 bg-white h-100 border border-red-200 justify-center">
<Tree
lineWidth={"2px"}
lineColor={"black"}
lineHeight={"40px"}
nodePadding={"5px"}
lineBorderRadius={"10px"}
label={
<div className="flex items-center justify-center" onClick={() => alert("hii")}>
<div className="border rounded rounded-md p-5 jusify-center" style={{backgroundColor: renderColor(tree?.data?.deposit?.name)}}>
<img className="w-16 h-16 rounded rounded-full mx-auto" src="/img/team-1-800x800.jpg" />
<p className="font-medium text-md pt-2 text-white">{tree?.data?.name}</p>
<p className="font-italic text-sm text-white">{tree?.data?.deposit?.name?.split(' ')[1]}</p>
</div>
</div>
}>
<RenderNode />
</Tree>
<Organizational/>
</div>
</div>
</div>
Expand Down
22 changes: 0 additions & 22 deletions styles/global.css
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

html,
body,
#__next {
height: 100%;
}

a {
color: inherit;
text-decoration: none;
}

* {
box-sizing: border-box;
}

0 comments on commit 4a44030

Please sign in to comment.