Skip to content

Commit 906af94

Browse files
committed
feat: pin archive and delete workspace functionality done
1 parent 2097c94 commit 906af94

File tree

7 files changed

+126
-19
lines changed

7 files changed

+126
-19
lines changed

src/app/api/user.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ export interface UserData {
77

88

99
export interface UserOrgs {
10-
[userName: string]: UserOrgDetails;
10+
userOrgs: UserOrgDetails;
1111
}
1212

1313
export interface UserOrgDetails {
14-
bookmark: string;
15-
role: string;
16-
archive: string;
14+
[key: string]: {
15+
bookmark: string;
16+
role: string;
17+
archive: string;
18+
};
19+
1720
}
1821

1922

@@ -82,7 +85,7 @@ export const setOrgArcheiveStatus = async (
8285
const respnse = await axios.put(
8386
url,
8487
{
85-
bookmarkStatus: status,
88+
archeiveStatus: status,
8689
},
8790
{
8891
headers: {
@@ -91,7 +94,9 @@ export const setOrgArcheiveStatus = async (
9194
},
9295
}
9396
);
97+
9498
return respnse;
99+
95100
};
96101

97102
export const getUserOrgs = async (

src/app/context/user/userContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UserOrgs } from "app/api/user";
1+
import { UserOrgDetails, UserOrgs } from "app/api/user";
22
import { createContext } from "react";
33

44
export interface UserContextType{

src/app/context/user/userState.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC, ReactNode, useState } from "react";
22
import UserContext from "./userContext";
3-
import { UserOrgs } from "app/api/user";
3+
import { UserOrgDetails, UserOrgs } from "app/api/user";
44

55
interface Props{
66
children: ReactNode

src/envConstants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const CLIENT_ID = '149d2857118e05e729a8';
22
export const BACKEND_URL = 'http://13.233.127.61:8080';
3-
export const AVATAR_API= "w9zrqHdDa4MsYB";
3+
export const AVATAR_API= "w9zrqHdDa4MsYB";
4+
5+
// http://13.233.127.61:8080

src/features/home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Home = () => {
3333
useState<ProjectsGithubData | null>(null);
3434
const [weeklyOrgProjectsData, setWeeklyOrgProjectsData] =
3535
useState<ProjectsGithubData | null>(null);
36-
const orgName = 'fordev';
36+
const orgName = 'yash';
3737

3838
const fetchOrgProjects = async () => {
3939
if (token) {

src/features/workspace-view/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ const WorkspaceView = () => {
1616
const navigate= useNavigate()
1717
const fetchData=async()=>{
1818

19-
if(token&&userContext?.username&&!userContext.userOrgs){
19+
if(token&&userContext?.username){
2020

2121
setIsLoad(true)
2222
try{
2323
const userOrgs= await getUserOrgs(token, userContext?.username.toString());
2424
userContext?.setUserOrgs(userOrgs.data)
25+
2526
}catch(e){
2627

2728
}
@@ -33,7 +34,7 @@ const WorkspaceView = () => {
3334

3435
useEffect(()=>{
3536
fetchData();
36-
},[userContext?.setUsername, userContext?.username,navigate])
37+
},[userContext?.setUsername, userContext?.username,navigate, userContext?.setUserOrgs])
3738

3839
return (
3940
<div className='workspaceview-container'>
@@ -51,7 +52,7 @@ const WorkspaceView = () => {
5152
return <WorkspaceCard
5253
key={orgName}
5354
workspaceName={orgName}
54-
archeive={"true"===details.archeive}
55+
archeive={"true"===details.archive}
5556
bookmark={"true"===details.bookmark}
5657
role={details.role}
5758
archeives={archeives}

src/features/workspace-view/workspace-card/index.tsx

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useContext, useEffect, useState } from 'react';
22
import './index.scss';
33
import rightNavbtn from '../../../app/assets/images/right_navigation_button.svg';
4-
import { getOrg, getOrgMembers } from 'app/api/organization';
4+
import { deleteOrg, getOrg, getOrgMembers } from 'app/api/organization';
55
import { deleteFile, getIcon } from 'app/api/file';
66
import { getMembers } from 'app/api/project';
7+
import UserContext from 'app/context/user/userContext';
8+
import toast from 'react-hot-toast';
9+
import { UserOrgDetails, UserOrgs, setOrgArcheiveStatus, setOrgBookmarkStatus } from 'app/api/user';
710

811
type workspaceCardProps = {
912
workspaceName: string;
@@ -15,6 +18,7 @@ type workspaceCardProps = {
1518
interface members{
1619
[username: string]: string
1720
}
21+
1822
const WorkspaceCard = (props: workspaceCardProps) => {
1923
const { workspaceName, role, archeive, bookmark ,archeives} = props;
2024
const [description,setDescription] = useState<null | string>(null)
@@ -23,6 +27,7 @@ const WorkspaceCard = (props: workspaceCardProps) => {
2327
const [fileName, setFileName]= useState<string|null>(null);
2428
const [imageSrc, setImageSrc] = useState<string | null>(null);
2529
const [members, setMembers]= useState<members|null>(null)
30+
const userContext= useContext(UserContext)
2631
const workSpaceData= async()=>{
2732
if(token&&workspaceName&&!workspaceName.endsWith("-userspace")){
2833
try{
@@ -53,10 +58,104 @@ const WorkspaceCard = (props: workspaceCardProps) => {
5358
}
5459

5560
useEffect(()=>{
61+
console.log(workspaceName,bookmark)
5662
workSpaceData()
57-
},[workspaceName])
63+
},[workspaceName, userContext?.setUserOrgs])
64+
65+
const HandleDelete= async()=>{
66+
if(!workspaceName.endsWith("-userspace")&&token){
67+
const func= async()=>{
68+
const res= await deleteOrg(token, workspaceName);
69+
const orgs= userContext?.userOrgs
70+
71+
if(orgs?.userOrgs.hasOwnProperty(workspaceName)){
72+
const obj: UserOrgDetails= orgs.userOrgs;
73+
delete obj[workspaceName];
74+
userContext?.setUserOrgs({
75+
userOrgs: obj
76+
})
77+
}
78+
79+
80+
81+
}
82+
toast.promise(func(), {
83+
loading: 'Deleting',
84+
success: <b>Successfully Deleted</b>,
85+
error: <b>Error while deleting</b>,
86+
});
87+
88+
}
89+
}
90+
5891

59-
92+
const HandlePin = async()=>{
93+
if(!workspaceName.endsWith("-userspace")&&token){
94+
const initBmk= bookmark
95+
const func=async()=>{
96+
let status: { [key: string]: boolean } = {
97+
[workspaceName]: !bookmark,
98+
};
99+
100+
101+
const res= await setOrgBookmarkStatus(token,status)
102+
const orgs= userContext?.userOrgs
103+
if(orgs?.userOrgs.hasOwnProperty(workspaceName)){
104+
105+
orgs.userOrgs[workspaceName].bookmark= (!bookmark).toString();
106+
userContext?.setUserOrgs(orgs);
107+
}
108+
}
109+
if(initBmk){
110+
toast.promise(func(), {
111+
loading: 'Unpinning',
112+
success: <b>Successfully unpinned</b>,
113+
error: <b>Error while unpinning</b>,
114+
});
115+
}
116+
else{
117+
toast.promise(func(), {
118+
loading: 'Pinning',
119+
success: <b>Successfully pinned</b>,
120+
error: <b>Error while pinning</b>,
121+
})
122+
}
123+
}
124+
}
125+
126+
const HandleArchive = async()=>{
127+
if(!workspaceName.endsWith("-userspace")&&token){
128+
const initArc= archeive
129+
const func=async()=>{
130+
let status: { [key: string]: boolean } = {
131+
[workspaceName]: !bookmark,
132+
};
133+
134+
135+
const res= await setOrgArcheiveStatus(token,status)
136+
const orgs= userContext?.userOrgs
137+
if(orgs?.userOrgs.hasOwnProperty(workspaceName)){
138+
139+
orgs.userOrgs[workspaceName].archive= (!bookmark).toString();
140+
userContext?.setUserOrgs(orgs);
141+
}
142+
}
143+
if(initArc){
144+
toast.promise(func(), {
145+
loading: 'Archiving',
146+
success: <b>Successfully archived</b>,
147+
error: <b>Error</b>,
148+
});
149+
}
150+
else{
151+
toast.promise(func(), {
152+
loading: 'Unarchiving',
153+
success: <b>Successfully unarchived</b>,
154+
error: <b>Error</b>,
155+
})
156+
}
157+
}
158+
}
60159

61160
return (
62161
<>
@@ -72,9 +171,9 @@ const WorkspaceCard = (props: workspaceCardProps) => {
72171
/>}
73172
</div>
74173
<div className={showPopUp ? 'workspace-popup' : 'hide'}>
75-
<div className='pin'>Pin</div>
76-
<div className='archive'>archive</div>
77-
<div className='delete' >delete</div>
174+
<div className='pin' onClick={HandlePin}>{bookmark?"UnPin":"Pin"}</div>
175+
<div className='archive' onClick={HandleArchive}>{archeive?"Unarchive":"archive"}</div>
176+
<div className='delete' onClick={HandleDelete}>delete</div>
78177
</div>
79178
<div className='workspace-card-utils'>
80179
<div className='workspace-logo'>

0 commit comments

Comments
 (0)