Skip to content

Commit

Permalink
feat: custom member selector dialog header
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-w committed Jan 7, 2025
1 parent 5d9e192 commit df42602
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
10 changes: 8 additions & 2 deletions apps/nestjs-backend/src/features/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Controller, Get, HttpCode, Post, Req, Res } from '@nestjs/common';
import type { IUserMeVo } from '@teable/openapi';
import { Response } from 'express';
import { ClsService } from 'nestjs-cls';
import { AUTH_SESSION_COOKIE_NAME } from '../../const';
import type { IClsStore } from '../../types/cls';
import { AuthService } from './auth.service';
import { TokenAccess } from './decorators/token.decorator';
import { SessionService } from './session/session.service';
Expand All @@ -10,7 +12,8 @@ import { SessionService } from './session/session.service';
export class AuthController {
constructor(
private readonly authService: AuthService,
private readonly sessionService: SessionService
private readonly sessionService: SessionService,
private readonly cls: ClsService<IClsStore>
) {}

@Post('signout')
Expand All @@ -22,7 +25,10 @@ export class AuthController {

@Get('/user/me')
async me(@Req() request: Express.Request) {
return request.user;
return {
...request.user,
organization: this.cls.get('organization'),
};
}

@Get('/user')
Expand Down
1 change: 0 additions & 1 deletion apps/nestjs-backend/test/base-query.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ describe('BaseSqlQuery e2e', () => {
from: table.id,
groupBy: [{ column: table.fields[0].id, type: BaseQueryColumnType.Field }],
});
console.log('res.data', res.data);
expect(res.data.columns).toHaveLength(1);
expect(res.data.rows).toEqual([
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export const Collaborator = (props: ICollaboratorProps) => {
{item.type === PrincipalType.User && (
<UserAvatar user={{ name: item.name, avatar: item.avatar }} />
)}
{item.type === PrincipalType.Department && <Building2 className="size-6" />}
{item.type === PrincipalType.Department && (
<div className=" flex size-7 items-center justify-center rounded-full bg-accent">
<Building2 className="size-4" />
</div>
)}
<div className="ml-2 flex flex-1 flex-col space-y-1">
<p className="text-sm font-medium leading-none">
{item.name}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, cn, DialogFooter, DialogHeader, DialogTitle, Separator } from '@teable/ui-lib';
import type { ReactNode } from 'react';
import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { useTranslation } from '../../context/app/i18n';
import { DepartmentList } from './DepartmentList';
Expand All @@ -11,6 +12,7 @@ interface IMemberContentProps {
departmentId?: string;
defaultSelectedMembers?: SelectedMemberWithData[];
disabledDepartment?: boolean;
header?: ReactNode;
onLoadData?: () => SelectedMemberWithData[];
onCancel?: () => void;
onConfirm?: (selectedMembers: SelectedMemberWithData[]) => void;
Expand All @@ -25,6 +27,7 @@ const _defaultSelectedMembers: SelectedMemberWithData[] = [];
export const MemberContent = forwardRef<IMemberContentRef, IMemberContentProps>(
(
{
header,
className,
departmentId,
defaultSelectedMembers,
Expand Down Expand Up @@ -74,7 +77,7 @@ export const MemberContent = forwardRef<IMemberContentRef, IMemberContentProps>(
return (
<div className={cn('flex flex-col gap-4', className)}>
<DialogHeader>
<DialogTitle>{t('memberSelector.title')}</DialogTitle>
<DialogTitle>{header ?? t('memberSelector.title')}</DialogTitle>
</DialogHeader>
<div className="mb-2">
<SearchInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IMemberSelectorDialogProps {
departmentId?: string;
children?: React.ReactNode;
disabledDepartment?: boolean;
header?: React.ReactNode;
onLoadData?: () => SelectedMemberWithData[];
onConfirm?: (members: SelectedMemberWithData[]) => void;
onCancel?: () => void;
Expand All @@ -25,12 +26,13 @@ export const MemberSelectorDialog = React.forwardRef<
>(
(
{
departmentId,
header,
children,
departmentId,
disabledDepartment,
defaultSelectedMembers,
onConfirm,
onCancel,
disabledDepartment,
onLoadData,
}: IMemberSelectorDialogProps,
ref
Expand Down Expand Up @@ -66,15 +68,16 @@ export const MemberSelectorDialog = React.forwardRef<
<DialogContent className="w-[80vw] min-w-[600px] max-w-6xl">
<MemberContent
ref={contentRef}
header={header}
className="h-[80vh]"
departmentId={departmentId}
disabledDepartment={disabledDepartment}
defaultSelectedMembers={defaultSelectedMembers}
onCancel={() => {
handleChange(false);
}}
onLoadData={onLoadData}
onConfirm={handleConfirm}
disabledDepartment={disabledDepartment}
/>
</DialogContent>
</Dialog>
Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/components/member-selector/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export * from './MemberSelectorDialog';
export * from './MemberContent';
export * from './DepartmentSelector';
export {
type SelectedMemberWithData as ISelectedMember,
TreeNodeType as MemberSelectorNodeType,
export { TreeNodeType as MemberSelectorNodeType } from './types';

export type {
SelectedMemberWithData as ISelectedMember,
SelectedUserWithData as ISelectedUser,
SelectedDepartmentWithData as ISelectedDepartment,
} from './types';
6 changes: 3 additions & 3 deletions packages/sdk/src/components/member-selector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export type SelectedDepartment = {

export type SelectedMember = SelectedUser | SelectedDepartment;

type SelectedUserWithData = SelectedUser & {
export interface SelectedUserWithData extends SelectedUser {
data: UserNode;
};
}

type SelectedDepartmentWithData = SelectedDepartment & {
export type SelectedDepartmentWithData = SelectedDepartment & {
data: DepartmentNode;
};

Expand Down

0 comments on commit df42602

Please sign in to comment.