feat: add project owner info on project settings page
This commit is contained in:
@@ -31,10 +31,12 @@ app.use('/', indexRoute);
|
|||||||
|
|
||||||
// "users"
|
// "users"
|
||||||
const usersIndexRoute = require('./routes/users/index')(sequelize);
|
const usersIndexRoute = require('./routes/users/index')(sequelize);
|
||||||
|
const usersShowRoute = require('./routes/users/show')(sequelize);
|
||||||
const usersFindRoute = require('./routes/users/find')(sequelize);
|
const usersFindRoute = require('./routes/users/find')(sequelize);
|
||||||
const signUpRoute = require('./routes/users/signup')(sequelize);
|
const signUpRoute = require('./routes/users/signup')(sequelize);
|
||||||
const signInRoute = require('./routes/users/signin')(sequelize);
|
const signInRoute = require('./routes/users/signin')(sequelize);
|
||||||
app.use('/users', usersIndexRoute);
|
app.use('/users', usersIndexRoute);
|
||||||
|
app.use('/users', usersShowRoute);
|
||||||
app.use('/users', usersFindRoute);
|
app.use('/users', usersFindRoute);
|
||||||
app.use('/users', signUpRoute);
|
app.use('/users', signUpRoute);
|
||||||
app.use('/users', signInRoute);
|
app.use('/users', signInRoute);
|
||||||
|
|||||||
36
backend/routes/users/show.js
Normal file
36
backend/routes/users/show.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const defineUser = require('../../models/users');
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const { verifySignedIn } = require('../../middleware/auth')(sequelize);
|
||||||
|
const User = defineUser(sequelize, DataTypes);
|
||||||
|
|
||||||
|
router.get('/:userId', verifySignedIn, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
if (!userId) {
|
||||||
|
return res.status(400).json({ error: 'userId is required' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await User.findByPk(userId, {
|
||||||
|
attributes: ['id', 'username', 'role', 'avatarPath'],
|
||||||
|
});
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).send('User not found');
|
||||||
|
}
|
||||||
|
res.json(user);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send('Internal Server Error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
@@ -296,6 +296,7 @@
|
|||||||
"project_management": "Project Management",
|
"project_management": "Project Management",
|
||||||
"project_name": "Project Name",
|
"project_name": "Project Name",
|
||||||
"project_detail": "Project Detail",
|
"project_detail": "Project Detail",
|
||||||
|
"project_owner": "Project Owner",
|
||||||
"edit_project": "Edit Project",
|
"edit_project": "Edit Project",
|
||||||
"project": "Project",
|
"project": "Project",
|
||||||
"publicity": "Publicity",
|
"publicity": "Publicity",
|
||||||
|
|||||||
@@ -296,6 +296,7 @@
|
|||||||
"project_management": "プロジェクト管理",
|
"project_management": "プロジェクト管理",
|
||||||
"project_name": "プロジェクト名",
|
"project_name": "プロジェクト名",
|
||||||
"project_detail": "プロジェクト詳細",
|
"project_detail": "プロジェクト詳細",
|
||||||
|
"project_owner": "所有者",
|
||||||
"edit_project": "プロジェクトの編集",
|
"edit_project": "プロジェクトの編集",
|
||||||
"project": "プロジェクト",
|
"project": "プロジェクト",
|
||||||
"publicity": "公開",
|
"publicity": "公開",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useState, useEffect, useContext } from 'react';
|
import { useState, useEffect, useContext } from 'react';
|
||||||
import { Button, Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from '@nextui-org/react';
|
import { Button, Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from '@nextui-org/react';
|
||||||
|
import Avatar from 'boring-avatars';
|
||||||
import { Pencil, Trash } from 'lucide-react';
|
import { Pencil, Trash } from 'lucide-react';
|
||||||
import { SettingsMessages } from '@/types/settings';
|
import { SettingsMessages } from '@/types/settings';
|
||||||
import { TokenContext } from '@/utils/TokenProvider';
|
import { TokenContext } from '@/utils/TokenProvider';
|
||||||
@@ -10,6 +11,9 @@ import { ProjectType } from '@/types/project';
|
|||||||
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog';
|
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog';
|
||||||
import { useRouter } from '@/src/navigation';
|
import { useRouter } from '@/src/navigation';
|
||||||
import ProjectDialog from '@/components/ProjectDialog';
|
import ProjectDialog from '@/components/ProjectDialog';
|
||||||
|
import Config from '@/config/config';
|
||||||
|
import { UserType } from '@/types/user';
|
||||||
|
const apiServer = Config.apiServer;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@@ -31,6 +35,37 @@ export default function SettingsPage({ projectId, messages, locale }: Props) {
|
|||||||
Folders: [],
|
Folders: [],
|
||||||
Runs: [],
|
Runs: [],
|
||||||
});
|
});
|
||||||
|
const [owner, setOwner] = useState<UserType>({
|
||||||
|
id: 0,
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
avatarPath: '',
|
||||||
|
role: -1,
|
||||||
|
username: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fetchUser(jwt: string, userId: string) {
|
||||||
|
const fetchOptions = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${jwt}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${apiServer}/users/${userId}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, fetchOptions);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('Error fetching data:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchDataEffect() {
|
async function fetchDataEffect() {
|
||||||
@@ -41,6 +76,13 @@ export default function SettingsPage({ projectId, messages, locale }: Props) {
|
|||||||
try {
|
try {
|
||||||
const data = await fetchProject(context.token.access_token, Number(projectId));
|
const data = await fetchProject(context.token.access_token, Number(projectId));
|
||||||
setProject(data);
|
setProject(data);
|
||||||
|
|
||||||
|
if (data.userId) {
|
||||||
|
const ownerData = await fetchUser(context.token.access_token, data.userId);
|
||||||
|
setOwner(ownerData);
|
||||||
|
} else {
|
||||||
|
console.error('failed to get project owner id');
|
||||||
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error in effect:', error.message);
|
console.error('Error in effect:', error.message);
|
||||||
}
|
}
|
||||||
@@ -99,15 +141,29 @@ export default function SettingsPage({ projectId, messages, locale }: Props) {
|
|||||||
<TableColumn>dummy</TableColumn>
|
<TableColumn>dummy</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow key="1">
|
<TableRow key="project-name">
|
||||||
<TableCell>{messages.projectName}</TableCell>
|
<TableCell>{messages.projectName}</TableCell>
|
||||||
<TableCell>{project.name}</TableCell>
|
<TableCell>{project.name}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow key="2">
|
<TableRow key="project-detail">
|
||||||
<TableCell>{messages.projectDetail}</TableCell>
|
<TableCell>{messages.projectDetail}</TableCell>
|
||||||
<TableCell>{project.detail}</TableCell>
|
<TableCell>{project.detail}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow key="3">
|
<TableRow key="project-owner">
|
||||||
|
<TableCell>{messages.projectOwner}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<Avatar
|
||||||
|
size={24}
|
||||||
|
name={owner.username}
|
||||||
|
variant="beam"
|
||||||
|
colors={['#0A0310', '#49007E', '#FF005B', '#FF7D10', '#FFB238']}
|
||||||
|
/>
|
||||||
|
<p className="">{owner.username}</p>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow key="project-publicity">
|
||||||
<TableCell>{messages.publicity}</TableCell>
|
<TableCell>{messages.publicity}</TableCell>
|
||||||
<TableCell>{project.isPublic ? messages.public : messages.private}</TableCell>
|
<TableCell>{project.isPublic ? messages.public : messages.private}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default function Page({ params }: { params: { projectId: string; locale:
|
|||||||
projectManagement: t('project_management'),
|
projectManagement: t('project_management'),
|
||||||
projectName: t('project_name'),
|
projectName: t('project_name'),
|
||||||
projectDetail: t('project_detail'),
|
projectDetail: t('project_detail'),
|
||||||
|
projectOwner: t('project_owner'),
|
||||||
editProject: t('edit_project'),
|
editProject: t('edit_project'),
|
||||||
project: t('project'),
|
project: t('project'),
|
||||||
ifYouMakePublic: t('if_you_make_public'),
|
ifYouMakePublic: t('if_you_make_public'),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export type SettingsMessages = {
|
|||||||
projectManagement: string;
|
projectManagement: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
projectDetail: string;
|
projectDetail: string;
|
||||||
|
projectOwner: string;
|
||||||
editProject: string;
|
editProject: string;
|
||||||
project: string;
|
project: string;
|
||||||
publicity: string;
|
publicity: string;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export type UserType = {
|
|||||||
username: string;
|
username: string;
|
||||||
role: number;
|
role: number;
|
||||||
avatarPath: string | null;
|
avatarPath: string | null;
|
||||||
} | null;
|
};
|
||||||
|
|
||||||
export type TokenProps = {
|
export type TokenProps = {
|
||||||
toastMessages: ToastMessages;
|
toastMessages: ToastMessages;
|
||||||
|
|||||||
Reference in New Issue
Block a user