Skip to content

Commit 0aa5242

Browse files
committed
feat: addProject pinProject ArchiveProject DeleteProject
1 parent 906af94 commit 0aa5242

File tree

19 files changed

+396
-250
lines changed

19 files changed

+396
-250
lines changed

src/app/components/buttonBar/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import TimeRangeSwitch from 'app/components/timeRangeSwitch';
33

44
import './index.scss';
55
const ButtonBar = () => {
6+
const [weeky, setWeekly]= useState<boolean>(true);
67
return (
78
<div className='project-upper-cont'>
89
<div className='button-bar'>
910
<button className='back-btn'>&larr; Back</button>
10-
<TimeRangeSwitch />
11+
<TimeRangeSwitch weekly={weeky} setWeekly={setWeekly}/>
1112
</div>
1213
<h1>Appetizer</h1>
1314
<p>

src/app/components/search/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useDispatch } from 'react-redux';
3-
import { searchAction } from 'features/home/slices/projectSearchSlice';
3+
import { searchAction } from 'features/workspace/slices/projectSearchSlice';
44
import search_icon from 'app/assets/images/search_icon.svg';
55
import './index.scss';
66

src/app/components/timeRangeSwitch/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ import { timeRangeModel } from 'features/project/components/contributorCard/type
44
import { weekAction, monthAction } from './timeRangeSlice';
55
import './index.scss';
66

7-
const TimeRangeSwitch = () => {
7+
interface Props{
8+
weekly: boolean,
9+
setWeekly: (bool: boolean)=>void
10+
}
11+
12+
const TimeRangeSwitch:React.FC<Props> = ({weekly, setWeekly}) => {
813
const dispatch = useDispatch();
914
const isWeekly = useSelector((state: timeRangeModel) => state.isWeekly.value);
1015

1116
return (
1217
<div className='timerange-cont'>
1318
<button
14-
onClick={() => dispatch(weekAction())}
15-
className={isWeekly ? 'active' : ''}
19+
onClick={() => setWeekly(!weekly)}
20+
className={weekly ? 'active' : ''}
1621
>
1722
Weekly{' '}
1823
</button>
1924
<button
20-
onClick={() => dispatch(monthAction())}
21-
className={isWeekly ? '' : 'active'}
25+
onClick={() => setWeekly(!weekly)}
26+
className={weekly ? '' : 'active'}
2227
>
2328
Monthly{' '}
2429
</button>

src/app/routes/BasicRoutes.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import React from 'react';
22
import { Routes, Route } from 'react-router-dom';
3-
import Home from 'features/home';
43
import ProjectPage from 'features/project';
54
import AddProject from 'features/AddProject';
65
import Error from 'features/Error';
76
import WorkspaceView from 'features/workspace-view';
87
import Login from 'features/login';
98
import AddWorkspace from 'features/AddWorkspace';
9+
import Workspace from 'features/workspace';
1010
const BasicRoutes = () => {
1111
return (
1212
<Routes>
13-
<Route path={'/'} element={<Home />} />
14-
<Route path={'/projects/:projectid'} element={<ProjectPage />} />
15-
<Route path={'/addproject'} element={<AddProject />} />
16-
<Route path={'/workspace-view'} element={<WorkspaceView />} />
13+
<Route path={'/'} element={<WorkspaceView />} />
14+
<Route path={'/projects/:projectName'} element={<ProjectPage />} />
15+
<Route path={'/addproject/:spaceName'} element={<AddProject />} />
16+
<Route path={'/workspace/:spaceName'} element={<Workspace />} />
1717
<Route path={'/login'} element={<Login />} />
1818
<Route path={'/addWorkspace'} element={<AddWorkspace />} />
1919
<Route path={'/*'} element={<Error />} />

src/app/state/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { combineReducers } from 'redux';
22
import { setAllUsernamesReducer, setUsernameReducer } from './usersReducers';
33
import timeRangeReducer from 'app/components/timeRangeSwitch/timeRangeSlice';
4-
import searchReducer from 'features/home/slices/projectSearchSlice';
4+
import searchReducer from 'features/workspace/slices/projectSearchSlice';
55
import { orgReducer } from './orgReducers';
66

77
export const reducers = combineReducers({

src/features/AddProject/index.tsx

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
import React, { ChangeEvent, useState } from 'react';
1+
import React, { ChangeEvent, useContext, useEffect, useState } from 'react';
22
import './index.scss';
33
import tick from '../../app/assets/images/tick.png';
4-
import { useNavigate } from 'react-router-dom';
4+
import { useNavigate, useParams } from 'react-router-dom';
55
import { getUser } from 'app/api/user';
66
import toast from 'react-hot-toast';
77
import { useQuery } from 'react-query';
88
import axios from 'axios';
99
import { addProject } from 'app/api/project';
10+
import UserContext from 'app/context/user/userContext';
11+
import { OrgProjects, Projects, getOrgProjects } from 'app/api/organization';
1012
const AddProject = () => {
1113
const navigate = useNavigate();
14+
const userContext = useContext(UserContext);
1215
const token = localStorage.getItem('token');
13-
const orgName = 'orgName';
16+
const { spaceName } = useParams();
1417
const [name, setName] = useState<string | null>(null);
1518
const [description, setDescription] = useState<string | null>(null);
1619
const [link, setLink] = useState<string | null>(null);
1720

18-
const [validLink, setValidLink] = useState<boolean>(false);
1921

20-
const [validName, setValidName] = useState<boolean>(false);
22+
const [orgProject, setOrgProjects] = useState<Projects | null>(null);
2123

22-
23-
24-
const linkChange = async (event: ChangeEvent<HTMLInputElement>) => {
25-
setLink(event.target.value);
26-
27-
if (isGitHubRepositoryLink(event.target.value)) {
24+
const fetchData = async () => {
25+
if (token && spaceName) {
2826
try {
29-
const response = await axios.get(event.target.value);
30-
setValidLink(true);
31-
return;
27+
const res = await getOrgProjects(token, spaceName);
28+
console.log(res.data.projects)
29+
setOrgProjects(res.data.projects);
3230
} catch (e) {}
3331
}
32+
};
3433

35-
setValidLink(false);
34+
useEffect(() => {
35+
fetchData();
36+
}, [spaceName]);
37+
38+
const linkChange = async (event: ChangeEvent<HTMLInputElement>) => {
39+
setLink(event.target.value);
3640
};
3741

3842
const nameChange = async (event: ChangeEvent<HTMLInputElement>) => {
3943
setName(event.target.value);
40-
setValidName(true);
4144
};
4245

4346
function isGitHubRepositoryLink(link: string): boolean {
@@ -49,39 +52,51 @@ const AddProject = () => {
4952
return githubRepoPattern.test(link);
5053
}
5154

55+
function isValidName(input: string): boolean {
56+
// Regular expression to match only alphanumeric characters, hyphens, and underscores
57+
const regex = /^[a-zA-Z0-9-_]+$/;
58+
59+
// Test if the input string matches the regular expression
60+
return regex.test(input);
61+
}
62+
63+
const isUnique= (name: string)=>{
64+
if(orgProject && name in orgProject){
65+
return false;
66+
}
67+
return true;
68+
}
69+
5270
const SubmitHandler = async () => {
5371
if (
72+
spaceName &&
5473
token &&
5574
name &&
56-
validName &&
57-
validLink &&
58-
description &&
5975
link &&
60-
description?.length > 3
76+
isValidName(name) &&
77+
isGitHubRepositoryLink(link) &&
78+
description &&
79+
80+
description?.length < 200
6181
) {
62-
try {
63-
const res = await addProject(token, orgName, {
82+
const func = async () => {
83+
const res = await addProject(token, spaceName, {
6484
name: name,
6585
description: description,
6686
link: link,
6787
});
68-
} catch (e) {
69-
toast.error('Error while saving');
70-
}
88+
navigate(`/workspace/${spaceName}`);
89+
};
90+
toast.promise(func(), {
91+
loading: 'Saving Project',
92+
success: <b>Project saved</b>,
93+
error: <b>Could not save</b>,
94+
});
95+
} else {
96+
toast.error('Invalid inputs');
7197
}
72-
73-
toast.error('Invalid inputs');
7498
};
7599

76-
77-
toast.promise(
78-
SubmitHandler(),{
79-
loading: 'Saving Project',
80-
success: <b>Project saved</b>,
81-
error:<b>Could not save</b>
82-
}
83-
)
84-
85100
return (
86101
<div>
87102
<div className='add-project-container'>
@@ -93,13 +108,18 @@ const AddProject = () => {
93108
onChange={nameChange}
94109
value={name ? name : ''}
95110
/>
111+
{!name ? 'Name feild should not be empty' : <></>}
112+
{name && !isValidName(name) && 'Not a valid name'}
113+
{name&&!isUnique(name)&&"This project name already exists"}
96114
<div className='input-title'>Project link</div>
97115
<input
98116
type='text'
99117
value={link ? link : ''}
100118
onChange={linkChange}
101119
placeholder='Github link of project'
102120
/>
121+
{!link ? 'Link feild should not be empty' : <></>}
122+
{link&&!isGitHubRepositoryLink(link)&&"Not a valid github repository link"}
103123
<div className='input-title'>Description</div>
104124
<input
105125
type='text'
@@ -109,8 +129,10 @@ const AddProject = () => {
109129
}
110130
placeholder='Details about project'
111131
/>
132+
{!description ? 'Description feild should not be empty' : <></>}
133+
{description&&description.length>=200&&"Description length should not be greater than 200"}
112134
</form>
113-
<button className='add-project-btn'>
135+
<button className='add-project-btn' onClick={SubmitHandler}>
114136
<img src={tick} alt='' /> Done
115137
</button>
116138
</div>

src/features/AddWorkspace/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const AddWorkspace = () => {
148148
}
149149

150150
}
151-
navigate('/workspace-view');
151+
navigate('/');
152152
};
153153

154154
toast.promise(func(), {

src/features/home/components/projectCard/index.tsx

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)