Skip to content

feat: Allow to update team name #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/gentle-lamps-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/api': patch
'@hyperdx/app': patch
---

feat: Allow to update team name
4 changes: 4 additions & 0 deletions packages/api/src/controllers/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export function rotateTeamApiKey(teamId: ObjectId) {
return Team.findByIdAndUpdate(teamId, { apiKey: uuidv4() }, { new: true });
}

export function setTeamName(teamId: ObjectId, name: string) {
return Team.findByIdAndUpdate(teamId, { name }, { new: true });
}

export async function getTags(teamId: ObjectId) {
const [dashboardTags, logViewTags] = await Promise.all([
Dashboard.aggregate([
Expand Down
29 changes: 28 additions & 1 deletion packages/api/src/routers/api/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { z } from 'zod';
import { validateRequest } from 'zod-express-middleware';

import * as config from '@/config';
import { getTags, getTeam, rotateTeamApiKey } from '@/controllers/team';
import {
getTags,
getTeam,
rotateTeamApiKey,
setTeamName,
} from '@/controllers/team';
import {
deleteTeamMember,
findUserByEmail,
Expand Down Expand Up @@ -78,6 +83,28 @@ router.patch('/apiKey', async (req, res, next) => {
}
});

router.patch(
'/name',
validateRequest({
body: z.object({
name: z.string().min(1).max(100),
}),
}),
async (req, res, next) => {
try {
const teamId = req.user?.team;
if (teamId == null) {
throw new Error(`User ${req.user?._id} not associated with a team`);
}
const { name } = req.body;
const team = await setTeamName(teamId, name);
res.json({ name: team?.name });
} catch (e) {
next(e);
}
},
);

router.post(
'/invitation',
validateRequest({
Expand Down
98 changes: 96 additions & 2 deletions packages/app/src/TeamPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react';
import { FormEventHandler, useCallback, useState } from 'react';
import Head from 'next/head';
import {
Button,
Expand Down Expand Up @@ -166,6 +166,7 @@ export default function TeamPage() {
const deleteTeamInvitation = api.useDeleteTeamInvitation();
const saveWebhook = api.useSaveWebhook();
const deleteWebhook = api.useDeleteWebhook();
const setTeamName = api.useSetTeamName();

const hasAdminAccess = true;

Expand Down Expand Up @@ -492,13 +493,43 @@ export default function TeamPage() {
],
});

const [isEditingTeamName, setIsEditingTeamName] = useState(false);
const [editingTeamNameValue, setEditingTeamNameValue] = useState('');
const handleSetTeamName = useCallback<FormEventHandler<HTMLFormElement>>(
e => {
e.stopPropagation();
e.preventDefault();
setTeamName.mutate(
{ name: editingTeamNameValue },
{
onError: e => {
notifications.show({
color: 'red',
message: 'Failed to update team name',
});
},
onSuccess: () => {
notifications.show({
color: 'green',
message: 'Updated team name',
});
refetchTeam();
setIsEditingTeamName(false);
setEditingTeamNameValue(team.name);
},
},
);
},
[editingTeamNameValue, refetchTeam, setTeamName, team?.name],
);

return (
<div className="TeamPage">
<Head>
<title>My Team - HyperDX</title>
</Head>
<div className={styles.header}>
<div>{team?.name || 'My team'}</div>
<div>Team Settings</div>
</div>
<div>
<Container>
Expand All @@ -509,6 +540,69 @@ export default function TeamPage() {
)}
{!isLoading && team != null && (
<Stack my={20} gap="xl">
<div className={styles.sectionHeader}>Team Name</div>
<Card>
{isEditingTeamName ? (
<form onSubmit={handleSetTeamName}>
<Group gap="xs">
<TextInput
size="xs"
value={editingTeamNameValue}
onChange={e => {
setEditingTeamNameValue(e.target.value);
}}
placeholder="My Team"
miw={300}
required
min={1}
max={100}
autoFocus
onKeyDown={e => {
if (e.key === 'Escape') {
setIsEditingTeamName(false);
}
}}
/>
<MButton
type="submit"
size="xs"
variant="light"
color="green"
loading={setTeamName.isLoading}
>
Save
</MButton>
<MButton
type="button"
size="xs"
variant="default"
disabled={setTeamName.isLoading}
onClick={() => setIsEditingTeamName(false)}
>
Cancel
</MButton>
</Group>
</form>
) : (
<Group gap="lg">
<div className="text-slate-300 fs-7">{team.name}</div>
<MButton
size="xs"
variant="default"
leftSection={
<i className="bi bi-pencil text-slate-300" />
}
onClick={() => {
setIsEditingTeamName(true);
setEditingTeamNameValue(team.name);
}}
>
Change
</MButton>
</Group>
)}
</Card>

<div className={styles.sectionHeader}>API Keys</div>
<Card>
<div className="mb-3 text-slate-300 fs-7">
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ const api = {
hdxServer(`team/members`).json(),
);
},
useSetTeamName() {
return useMutation<any, HTTPError, { name: string }>(async ({ name }) =>
hdxServer(`team/name`, {
method: 'PATCH',
json: { name },
}).json(),
);
},
useTags() {
return useQuery<{ data: string[] }, HTTPError>(`team/tags`, () =>
hdxServer(`team/tags`).json<{ data: string[] }>(),
Expand Down