builds backend initated
This commit is contained in:
parent
44f209ae1f
commit
a5a7a7e7b5
|
|
@ -6,7 +6,7 @@ import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
import { UsersModule } from './users/users.module';
|
import { UsersModule } from './users/users.module';
|
||||||
import { PeopleModule } from './people/people.module';
|
import { PeopleModule } from './people/people.module';
|
||||||
import { BuildModule } from './build/build.module';
|
import { BuildModule } from './builds/build.module';
|
||||||
import { BuildPartsModule } from './build-parts/build-parts.module';
|
import { BuildPartsModule } from './build-parts/build-parts.module';
|
||||||
import { BuildAreaModule } from './build-area/build-area.module';
|
import { BuildAreaModule } from './build-area/build-area.module';
|
||||||
import { UserTypesModule } from './user-types/user-types.module';
|
import { UserTypesModule } from './user-types/user-types.module';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { ExpiryBaseInput } from "@/models/base.model";
|
||||||
import { InputType, Field } from "@nestjs/graphql";
|
import { InputType, Field } from "@nestjs/graphql";
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class UpdateBuildIbanInput {
|
export class UpdateBuildIbanInput extends ExpiryBaseInput {
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field({ nullable: true })
|
||||||
iban?: string;
|
iban?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { InputType, Field } from '@nestjs/graphql';
|
import { InputType, Field, ID } from '@nestjs/graphql';
|
||||||
|
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class CreateBuildPartsInput {
|
export class CreateBuildPartsInput {
|
||||||
|
|
||||||
@Field()
|
@Field(() => ID)
|
||||||
uuid: string;
|
build: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { ObjectType, Field } from "@nestjs/graphql";
|
import { ObjectType, Field } from "@nestjs/graphql";
|
||||||
import { BuildSites } from "@/models/build-site.model";
|
import { BuildSites } from "@/models/build-site.model";
|
||||||
|
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class ListBuildSitesResponse {
|
export class ListBuildSitesResponse {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
|
||||||
import { Types } from 'mongoose';
|
|
||||||
import { Build } from '@/models/build.model';
|
|
||||||
import { CreateBuildInput } from './dto/create-build.input';
|
|
||||||
import graphqlFields from 'graphql-fields';
|
|
||||||
import { BuildService } from './build.service';
|
|
||||||
import type { GraphQLResolveInfo } from 'graphql';
|
|
||||||
|
|
||||||
@Resolver()
|
|
||||||
export class BuildResolver {
|
|
||||||
|
|
||||||
constructor(private readonly buildService: BuildService) { }
|
|
||||||
|
|
||||||
@Query(() => [Build], { name: 'Builds' })
|
|
||||||
async getBuilds(@Info() info: GraphQLResolveInfo): Promise<Build[]> {
|
|
||||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findAll(projection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query(() => Build, { name: 'Build', nullable: true })
|
|
||||||
async getBuild(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<Build | null> {
|
|
||||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findById(new Types.ObjectId(id), projection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mutation(() => Build, { name: 'createBuild' })
|
|
||||||
async createBuild(@Args('input') input: CreateBuildInput): Promise<Build> {
|
|
||||||
return this.buildService.create(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { InjectModel } from '@nestjs/mongoose';
|
|
||||||
import { Types, Model } from 'mongoose';
|
|
||||||
import { Build, BuildDocument } from '@/models/build.model';
|
|
||||||
import { CreateBuildInput } from './dto/create-build.input';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BuildService {
|
|
||||||
|
|
||||||
constructor(@InjectModel(Build.name) private readonly buildModel: Model<BuildDocument>) { }
|
|
||||||
|
|
||||||
async findAll(projection?: any): Promise<BuildDocument[]> {
|
|
||||||
return this.buildModel.find({}, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
async findById(id: Types.ObjectId, projection?: any): Promise<BuildDocument | null> {
|
|
||||||
return this.buildModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(input: CreateBuildInput): Promise<BuildDocument> { const buildArea = new this.buildModel(input); return buildArea.save() }
|
|
||||||
|
|
||||||
buildProjection(fields: Record<string, any>): any {
|
|
||||||
const projection: any = {};
|
|
||||||
for (const key in fields) {
|
|
||||||
if (key === 'buildArea' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildArea.${subField}`] = 1 } }
|
|
||||||
else { projection[key] = 1 }
|
|
||||||
}
|
|
||||||
return projection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import { InputType, Field } from "@nestjs/graphql";
|
|
||||||
|
|
||||||
@InputType()
|
|
||||||
export class UpdateBuildAttributeInput {
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
buildType?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
site?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
address?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
areas?: string[];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@InputType()
|
|
||||||
export class UpdateBuildResponsibleInput {
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
company?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
person?: string;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||||
|
import { Types } from 'mongoose';
|
||||||
|
import { Build } from '@/models/build.model';
|
||||||
|
import { CreateBuildInput } from './dto/create-build.input';
|
||||||
|
import { UpdateBuildResponsibleInput, UpdateBuildAttributeInput } from './dto/update-build.input';
|
||||||
|
import graphqlFields from 'graphql-fields';
|
||||||
|
import { BuildService } from './build.service';
|
||||||
|
import type { GraphQLResolveInfo } from 'graphql';
|
||||||
|
import { ListArguments } from '@/dto/list.input';
|
||||||
|
import { ListBuildResponse } from './dto/list-build.response';
|
||||||
|
|
||||||
|
@Resolver()
|
||||||
|
export class BuildResolver {
|
||||||
|
|
||||||
|
constructor(private readonly buildService: BuildService) { }
|
||||||
|
|
||||||
|
@Query(() => ListBuildResponse, { name: 'builds' })
|
||||||
|
async getBuilds(@Info() info: GraphQLResolveInfo, @Args('input') input: ListArguments): Promise<ListBuildResponse> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findAll(projection, input.skip, input.limit, input.sort, input.filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => Build, { name: 'build', nullable: true })
|
||||||
|
async getBuild(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<Build | null> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findById(new Types.ObjectId(id), projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mutation(() => Build, { name: 'createBuild' })
|
||||||
|
async createBuild(@Args('input') input: CreateBuildInput): Promise<Build> { return this.buildService.create(input) }
|
||||||
|
|
||||||
|
@Mutation(() => Build, { name: 'updateBuildResponsible' })
|
||||||
|
async updateBuildResponsible(@Args('uuid', { type: () => ID }) uuid: string, @Args('input') input: UpdateBuildResponsibleInput): Promise<Build> {
|
||||||
|
return this.buildService.updateResponsible(uuid, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mutation(() => Build, { name: 'updateBuildAttribute' })
|
||||||
|
async updateBuildAttribute(@Args('uuid', { type: () => ID }) uuid: string, @Args('input') input: UpdateBuildAttributeInput): Promise<Build> {
|
||||||
|
return this.buildService.updateAttribute(uuid, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { Types, Model } from 'mongoose';
|
||||||
|
import { Build, BuildDocument } from '@/models/build.model';
|
||||||
|
import { CreateBuildInput } from './dto/create-build.input';
|
||||||
|
import { UpdateBuildAttributeInput, UpdateBuildResponsibleInput } from './dto/update-build.input';
|
||||||
|
import { ListBuildResponse } from './dto/list-build.response';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BuildService {
|
||||||
|
|
||||||
|
constructor(@InjectModel(Build.name) private readonly buildModel: Model<BuildDocument>) { }
|
||||||
|
|
||||||
|
async findAll(projection: any, skip: number, limit: number, sort?: Record<string, 1 | -1>, filters?: Record<string, any>): Promise<ListBuildResponse> {
|
||||||
|
const query: any = {}; if (filters && Object.keys(filters).length > 0) { Object.assign(query, filters) };
|
||||||
|
const totalCount = await this.buildModel.countDocuments(query).exec();
|
||||||
|
const data = await this.buildModel.find(query).skip(skip).limit(limit).sort(sort).exec();
|
||||||
|
return { data, totalCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
async findById(id: Types.ObjectId, projection?: any): Promise<BuildDocument | null> {
|
||||||
|
return this.buildModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(input: CreateBuildInput): Promise<BuildDocument> { const buildArea = new this.buildModel(input); return buildArea.save() }
|
||||||
|
|
||||||
|
async updateResponsible(uuid: string, input: UpdateBuildResponsibleInput): Promise<BuildDocument> {
|
||||||
|
const build = await this.buildModel.findOne({ uuid }); if (!build) { throw new Error('Build not found') }; build.set({ responsible: input }); return build.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAttribute(uuid: string, input: UpdateBuildAttributeInput): Promise<BuildDocument> {
|
||||||
|
const build = await this.buildModel.findOne({ uuid }); if (!build) { throw new Error('Build not found') }; build.set({ attribute: input }); return build.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
buildProjection(fields: Record<string, any>): any {
|
||||||
|
const projection: any = {};
|
||||||
|
for (const key in fields) {
|
||||||
|
if (key === 'build' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`build.${subField}`] = 1 } }
|
||||||
|
else { projection[key] = 1 }
|
||||||
|
}
|
||||||
|
return projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ExpiryBaseInput } from "@/models/base.model";
|
||||||
import { InputType, Field, ID } from "@nestjs/graphql";
|
import { InputType, Field, ID } from "@nestjs/graphql";
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
|
|
@ -54,7 +55,7 @@ export class CreateBuildInfoInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class CreateBuildInput {
|
export class CreateBuildInput extends ExpiryBaseInput {
|
||||||
|
|
||||||
@Field(() => ID)
|
@Field(() => ID)
|
||||||
buildType: string;
|
buildType: string;
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Build } from "@/models/build.model";
|
||||||
|
import { Field, Int, ObjectType } from "@nestjs/graphql";
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class ListBuildResponse {
|
||||||
|
|
||||||
|
@Field(() => [Build], { nullable: true })
|
||||||
|
data?: Build[];
|
||||||
|
|
||||||
|
@Field(() => Int, { nullable: true })
|
||||||
|
totalCount?: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { InputType, Field, ID } from "@nestjs/graphql";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateResponsibleInput {
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
company?: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
person?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateBuildAttributeInput {
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
site?: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
address?: string;
|
||||||
|
|
||||||
|
@Field(() => [ID], { nullable: true })
|
||||||
|
areas?: string[];
|
||||||
|
|
||||||
|
@Field(() => [ID], { nullable: true })
|
||||||
|
ibans?: string[];
|
||||||
|
|
||||||
|
@Field(() => [UpdateResponsibleInput], { nullable: true })
|
||||||
|
responsibles?: UpdateResponsibleInput[];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateBuildResponsibleInput {
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
company?: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
person?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
mutation CreateBuild($input: CreateBuildInput!) {
|
||||||
|
createBuild(input: $input) {
|
||||||
|
_id
|
||||||
|
uuid
|
||||||
|
createdAt
|
||||||
|
expiryStarts
|
||||||
|
expiryEnds
|
||||||
|
buildType
|
||||||
|
collectionToken
|
||||||
|
ibans
|
||||||
|
responsibles {
|
||||||
|
company
|
||||||
|
person
|
||||||
|
}
|
||||||
|
areas
|
||||||
|
info {
|
||||||
|
govAddressCode
|
||||||
|
buildName
|
||||||
|
buildNo
|
||||||
|
maxFloor
|
||||||
|
undergroundFloor
|
||||||
|
buildDate
|
||||||
|
decisionPeriodDate
|
||||||
|
taxNo
|
||||||
|
liftCount
|
||||||
|
heatingSystem
|
||||||
|
coolingSystem
|
||||||
|
hotWaterSystem
|
||||||
|
blockServiceManCount
|
||||||
|
securityServiceManCount
|
||||||
|
garageCount
|
||||||
|
managementRoomId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
"input": {
|
||||||
|
"expiryStarts": "2025-01-10T08:00:00.000Z",
|
||||||
|
"expiryEnds": "2099-12-31T00:00:00.000Z",
|
||||||
|
"buildType": "675abc12ef90123456789aaa",
|
||||||
|
"collectionToken": "COLL-TEST-2025-XYZ",
|
||||||
|
"info": {
|
||||||
|
"govAddressCode": "TR-34-12345",
|
||||||
|
"buildName": "Aether Residence",
|
||||||
|
"buildNo": "B-12",
|
||||||
|
"maxFloor": 12,
|
||||||
|
"undergroundFloor": 2,
|
||||||
|
"buildDate": "2020-06-15T00:00:00.000Z",
|
||||||
|
"decisionPeriodDate": "2020-05-01T00:00:00.000Z",
|
||||||
|
"taxNo": "12345678901",
|
||||||
|
"liftCount": 3,
|
||||||
|
"heatingSystem": true,
|
||||||
|
"coolingSystem": true,
|
||||||
|
"hotWaterSystem": true,
|
||||||
|
"blockServiceManCount": 2,
|
||||||
|
"securityServiceManCount": 1,
|
||||||
|
"garageCount": 30,
|
||||||
|
"managementRoomId": 101
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,75 +1,75 @@
|
||||||
import { Prop } from '@nestjs/mongoose';
|
import { Prop } from '@nestjs/mongoose';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { ObjectType, InputType, Field, ID } from '@nestjs/graphql';
|
import { ObjectType, InputType, Field } from '@nestjs/graphql';
|
||||||
|
|
||||||
@ObjectType({ isAbstract: true })
|
@ObjectType({ isAbstract: true })
|
||||||
export class Base {
|
export class Base {
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID, unique: true })
|
@Prop({ default: () => randomUUID(), unique: true })
|
||||||
uuid: string;
|
uuid: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: () => new Date(Date.now()) })
|
@Prop({ default: () => new Date(Date.now()) })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: () => new Date(Date.now()) })
|
@Prop({ default: () => new Date(Date.now()) })
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: false, required: false })
|
@Prop({ default: false, required: false })
|
||||||
isConfirmed?: boolean;
|
isConfirmed?: boolean;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: false, required: false })
|
@Prop({ default: false, required: false })
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: true, required: false })
|
@Prop({ default: true, required: false })
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID })
|
@Prop({ default: randomUUID })
|
||||||
crypUuId: string;
|
crypUuId: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID })
|
@Prop({ default: randomUUID })
|
||||||
createdCredentialsToken: string;
|
createdCredentialsToken: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID })
|
@Prop({ default: randomUUID })
|
||||||
updatedCredentialsToken: string;
|
updatedCredentialsToken: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID })
|
@Prop({ default: randomUUID })
|
||||||
confirmedCredentialsToken: string;
|
confirmedCredentialsToken: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: false, required: false })
|
@Prop({ default: false, required: false })
|
||||||
isNotificationSend?: boolean;
|
isNotificationSend?: boolean;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: false, required: false })
|
@Prop({ default: false, required: false })
|
||||||
isEmailSend?: boolean;
|
isEmailSend?: boolean;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: 0 })
|
@Prop({ default: 0 })
|
||||||
refInt: number;
|
refInt: number;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: randomUUID })
|
@Prop({ default: randomUUID })
|
||||||
refId: string;
|
refId: string;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: 0 })
|
@Prop({ default: 0 })
|
||||||
replicationId: number;
|
replicationId: number;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: () => new Date(Date.now()), required: false })
|
@Prop({ default: () => new Date(Date.now()), required: false })
|
||||||
expiryStarts?: Date;
|
expiryStarts?: Date;
|
||||||
|
|
||||||
@Field()
|
@Field({ nullable: true })
|
||||||
@Prop({ default: () => new Date('2099-12-31'), required: false })
|
@Prop({ default: () => new Date('2099-12-31'), required: false })
|
||||||
expiryEnds?: Date;
|
expiryEnds?: Date;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||||
import { Document, Types } from 'mongoose';
|
import { Document, Types } from 'mongoose';
|
||||||
import { ObjectType, Field, ID, Int } from '@nestjs/graphql';
|
import { ObjectType, Field, ID, Int } from '@nestjs/graphql';
|
||||||
import { Base, ChangableBase } from '@/models/base.model';
|
import { Base } from '@/models/base.model';
|
||||||
import { Person } from '@/models/person.model';
|
import { Person } from '@/models/person.model';
|
||||||
import { Company } from '@/models/company.model';
|
import { Company } from '@/models/company.model';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@Schema({ timestamps: true })
|
@Schema({ timestamps: true })
|
||||||
export class BuildIban extends ChangableBase {
|
export class BuildIban extends Base {
|
||||||
|
|
||||||
@Field(() => ID)
|
@Field(() => ID)
|
||||||
readonly _id: string;
|
readonly _id: string;
|
||||||
|
|
@ -37,13 +37,13 @@ export class BuildIban extends ChangableBase {
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class BuildResponsible {
|
export class BuildResponsible {
|
||||||
|
|
||||||
@Field(() => ID)
|
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||||
@Prop({ type: Types.ObjectId, ref: Company.name, required: true })
|
@Prop({ type: [String], default: [] })
|
||||||
company: Types.ObjectId;
|
company?: string[];
|
||||||
|
|
||||||
@Field(() => ID)
|
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||||
@Prop({ type: Types.ObjectId, ref: Person.name, required: true })
|
@Prop({ type: [String], default: [] })
|
||||||
person: Types.ObjectId;
|
person?: string[];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,38 +118,45 @@ export class BuildInfo {
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@Schema({ timestamps: true })
|
@Schema({ timestamps: true })
|
||||||
export class Build extends Base {
|
export class Build {
|
||||||
|
|
||||||
@Field(() => ID)
|
|
||||||
@Prop({ type: Types.ObjectId, ref: 'BuildType', required: true })
|
|
||||||
buildType: Types.ObjectId;
|
|
||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
@Prop({ required: true, unique: true })
|
readonly _id: string;
|
||||||
|
|
||||||
|
// @Field(() => ID)
|
||||||
|
// @Prop({ type: Types.ObjectId, ref: 'BuildType', required: true })
|
||||||
|
// buildType: Types.ObjectId;
|
||||||
|
|
||||||
|
@Field(() => String, { nullable: true })
|
||||||
|
@Prop({ required: true })
|
||||||
|
buildType: string;
|
||||||
|
|
||||||
|
@Field(() => String, { nullable: true })
|
||||||
|
@Prop({ required: true })
|
||||||
collectionToken: string;
|
collectionToken: string;
|
||||||
|
|
||||||
@Field(() => BuildInfo)
|
@Field(() => BuildInfo, { nullable: true })
|
||||||
@Prop({ type: BuildInfo, required: true })
|
@Prop({ type: BuildInfo, required: true })
|
||||||
info: BuildInfo;
|
info: BuildInfo;
|
||||||
|
|
||||||
@Field(() => ID, { nullable: true })
|
@Field(() => String, { nullable: true })
|
||||||
@Prop({ type: Types.ObjectId, ref: 'BuildSites' })
|
@Prop({ type: String })
|
||||||
site?: Types.ObjectId;
|
site?: string;
|
||||||
|
|
||||||
@Field(() => ID, { nullable: true })
|
@Field(() => String, { nullable: true })
|
||||||
@Prop({ type: Types.ObjectId, ref: 'BuildAddress' })
|
@Prop({ type: String })
|
||||||
address?: Types.ObjectId;
|
address?: string;
|
||||||
|
|
||||||
@Field(() => [ID], { nullable: true })
|
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||||
@Prop({ type: [{ type: Types.ObjectId, ref: 'BuildArea' }] })
|
@Prop({ type: [String], default: [] })
|
||||||
areas?: Types.ObjectId[];
|
areas?: string[];
|
||||||
|
|
||||||
@Field(() => [BuildIban], { nullable: true })
|
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||||
@Prop({ type: [BuildIban] })
|
@Prop({ type: [String], default: [] })
|
||||||
ibans?: BuildIban[];
|
ibans?: string[];
|
||||||
|
|
||||||
@Field(() => [BuildResponsible], { nullable: true })
|
@Field(() => [BuildResponsible], { nullable: true, defaultValue: [] })
|
||||||
@Prop({ type: [BuildResponsible] })
|
@Prop({ type: [BuildResponsible], default: [] })
|
||||||
responsibles?: BuildResponsible[];
|
responsibles?: BuildResponsible[];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,30 @@
|
||||||
'use server';
|
'use server';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { GraphQLClient, gql } from 'graphql-request';
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
import { buildTypesAddSchema } from './schema';
|
import { buildIbansAddSchema } from './schema';
|
||||||
|
|
||||||
const endpoint = "http://localhost:3001/graphql";
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const validatedBody = buildTypesAddSchema.parse(body);
|
const validatedBody = buildIbansAddSchema.parse(body);
|
||||||
try {
|
try {
|
||||||
const client = new GraphQLClient(endpoint);
|
const client = new GraphQLClient(endpoint);
|
||||||
const query = gql`
|
const query = gql`
|
||||||
mutation CreateBuildAddress($input: CreateBuildAddressInput!) {
|
mutation CreateBuildIban($input: CreateBuildIbanInput!) {
|
||||||
createBuildAddress(input: $input) {
|
createBuildIban(input: $input) {
|
||||||
_id
|
_id
|
||||||
buildNumber
|
uuid
|
||||||
doorNumber
|
createdAt
|
||||||
floorNumber
|
updatedAt
|
||||||
commentAddress
|
expiryEnds
|
||||||
letterAddress
|
expiryStarts
|
||||||
shortLetterAddress
|
|
||||||
latitude
|
|
||||||
longitude
|
|
||||||
street
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const variables = { input: validatedBody };
|
const variables = { input: validatedBody };
|
||||||
const data = await client.request(query, variables);
|
const data = await client.request(query, variables);
|
||||||
return NextResponse.json({ data: data.createBuildAddress, status: 200 });
|
return NextResponse.json({ data: data.createBuildIban, status: 200 });
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const buildTypesAddSchema = z.object({
|
export const buildIbansAddSchema = z.object({
|
||||||
buildNumber: z.string(),
|
|
||||||
doorNumber: z.string(),
|
iban: z.string(),
|
||||||
floorNumber: z.string(),
|
startDate: z.string(),
|
||||||
commentAddress: z.string(),
|
stopDate: z.string(),
|
||||||
letterAddress: z.string(),
|
bankCode: z.string(),
|
||||||
shortLetterAddress: z.string(),
|
xcomment: z.string(),
|
||||||
latitude: z.number(),
|
expiryStarts: z.string().optional(),
|
||||||
longitude: z.number(),
|
expiryEnds: z.string().optional(),
|
||||||
street: z.string().optional(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type BuildTypesAdd = z.infer<typeof buildTypesAddSchema>;
|
export type BuildIbansAdd = z.infer<typeof buildIbansAddSchema>;
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,17 @@ export async function POST(request: Request) {
|
||||||
query BuildIbans($input: ListArguments!) {
|
query BuildIbans($input: ListArguments!) {
|
||||||
buildIbans(input: $input) {
|
buildIbans(input: $input) {
|
||||||
data {
|
data {
|
||||||
|
_id
|
||||||
|
uuid
|
||||||
iban
|
iban
|
||||||
startDate
|
startDate
|
||||||
stopDate
|
stopDate
|
||||||
bankCode
|
bankCode
|
||||||
xcomment
|
xcomment
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
expiryStarts
|
||||||
|
expiryEnds
|
||||||
}
|
}
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use server';
|
'use server';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { GraphQLClient, gql } from 'graphql-request';
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
import { UpdateBuildAddressSchema } from './schema';
|
import { UpdateBuildIbansSchema } from './schema';
|
||||||
|
|
||||||
const endpoint = "http://localhost:3001/graphql";
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
|
@ -9,29 +9,26 @@ export async function POST(request: Request) {
|
||||||
const searchUrl = new URL(request.url);
|
const searchUrl = new URL(request.url);
|
||||||
const uuid = searchUrl.searchParams.get("uuid") || "";
|
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const validatedBody = UpdateBuildAddressSchema.parse(body);
|
const validatedBody = UpdateBuildIbansSchema.parse(body);
|
||||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||||
try {
|
try {
|
||||||
const client = new GraphQLClient(endpoint);
|
const client = new GraphQLClient(endpoint);
|
||||||
const query = gql`
|
const query = gql`
|
||||||
mutation UpdateBuildAddress($uuid: String!, $input: UpdateBuildAddressInput!) {
|
mutation UpdateBuildIban($uuid:String!,$input: UpdateBuildIbanInput!) {
|
||||||
updateBuildAddress(uuid: $uuid, input: $input) {
|
updateBuildIban(uuid: $uuid,input: $input) {
|
||||||
_id
|
_id
|
||||||
buildNumber
|
uuid
|
||||||
doorNumber
|
xcomment
|
||||||
floorNumber
|
createdAt
|
||||||
commentAddress
|
updatedAt
|
||||||
letterAddress
|
expiryEnds
|
||||||
shortLetterAddress
|
expiryStarts
|
||||||
latitude
|
|
||||||
longitude
|
|
||||||
street
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const variables = { uuid: uuid, input: validatedBody };
|
const variables = { uuid: uuid, input: validatedBody };
|
||||||
const data = await client.request(query, variables);
|
const data = await client.request(query, variables);
|
||||||
return NextResponse.json({ data: data.updateBuildAddress, status: 200 });
|
return NextResponse.json({ data: data.updateBuildIban, status: 200 });
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const UpdateBuildAddressSchema = z.object({
|
export const UpdateBuildIbansSchema = z.object({
|
||||||
buildNumber: z.string().optional(),
|
|
||||||
doorNumber: z.string().optional(),
|
iban: z.string().optional(),
|
||||||
floorNumber: z.string().optional(),
|
startDate: z.string().optional(),
|
||||||
commentAddress: z.string().optional(),
|
stopDate: z.string().optional(),
|
||||||
letterAddress: z.string().optional(),
|
bankCode: z.string().optional(),
|
||||||
shortLetterAddress: z.string().optional(),
|
xcomment: z.string().optional(),
|
||||||
latitude: z.number().optional(),
|
expiryStarts: z.string().optional(),
|
||||||
longitude: z.number().optional(),
|
expiryEnds: z.string().optional(),
|
||||||
street: z.string().optional(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type UpdateBuildAddress = z.infer<typeof UpdateBuildAddressSchema>;
|
export type UpdateBuildIbans = z.infer<typeof UpdateBuildIbansSchema>;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
import { PageAddBuildAreas } from "@/pages/build-areas/add/page";
|
||||||
|
|
||||||
const BuildAreasAdd = () => { return <><div>BuildAreasAdd</div></> }
|
const BuildAreasAdd = () => { return <><div><PageAddBuildAreas /></div></> }
|
||||||
|
|
||||||
export default BuildAreasAdd;
|
export default BuildAreasAdd;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { PageBuildAreas } from "@/pages/build-areas/page";
|
||||||
|
|
||||||
const BuildAreas = () => {
|
const BuildAreas = () => {
|
||||||
return <><div>BuildAreas</div></>
|
return <><div><PageBuildAreas /></div></>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BuildAreas;
|
export default BuildAreas;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
|
import { PageUpdateBuildSites } from "@/pages/build-areas/update/page";
|
||||||
|
|
||||||
const BuildAreasUpdate = () => {
|
const BuildAreasUpdate = () => { return <><div><PageUpdateBuildSites /></div></> }
|
||||||
return <><div>BuildAreasUpdate</div></>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default BuildAreasUpdate;
|
export default BuildAreasUpdate;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
import { PageAddBuildIbans } from "@/pages/build-ibans/add/page";
|
||||||
|
|
||||||
const BuildIbansAdd = () => { return <><div>BuildIbansAdd</div></> }
|
const BuildIbansAdd = () => { return <><PageAddBuildIbans /></> }
|
||||||
|
|
||||||
export default BuildIbansAdd;
|
export default BuildIbansAdd;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
|
import { PageBuildIbans } from "@/pages/build-ibans/page";
|
||||||
|
|
||||||
const BuildIbans = () => {
|
const BuildIbans = () => { return <><PageBuildIbans /></> }
|
||||||
return <><div>BuildIbans</div></>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default BuildIbans;
|
export default BuildIbans;
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { PageUpdateBuildIbans } from "@/pages/build-ibans/update/page";
|
||||||
|
|
||||||
const BuildIbansUpdate = () => {
|
const BuildIbansUpdate = () => {
|
||||||
return <><div>BuildIbansUpdate</div></>
|
return <><PageUpdateBuildIbans /></>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BuildIbansUpdate;
|
export default BuildIbansUpdate;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageAddBuildIbans } from "@/pages/build-ibans/add/page";
|
||||||
|
|
||||||
|
const BuildPartsAdd = () => { return <><PageAddBuildIbans /></> }
|
||||||
|
|
||||||
|
export default BuildPartsAdd;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageBuildIbans } from "@/pages/build-ibans/page";
|
||||||
|
|
||||||
|
const BuildParts = () => { return <><PageBuildIbans /></> }
|
||||||
|
|
||||||
|
export default BuildParts;
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { PageUpdateBuildIbans } from "@/pages/build-ibans/update/page";
|
||||||
|
|
||||||
|
const BuildPartsUpdate = () => {
|
||||||
|
return <><PageUpdateBuildIbans /></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BuildPartsUpdate;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageAddBuildTypes } from "@/pages/build-types/add/page";
|
||||||
|
|
||||||
|
const AddBuildPage = () => { return <><PageAddBuildTypes /></> }
|
||||||
|
|
||||||
|
export default AddBuildPage;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageBuilds } from "@/pages/builds/page";
|
||||||
|
|
||||||
|
const BuildPage = () => { return <><PageBuilds /></> }
|
||||||
|
|
||||||
|
export default BuildPage;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageUpdateBuildTypes } from '@/pages/build-types/update/page';
|
||||||
|
|
||||||
|
const UpdateBuildPage = async () => { return <PageUpdateBuildTypes /> }
|
||||||
|
|
||||||
|
export default UpdateBuildPage;
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import {
|
import {
|
||||||
IconInnerShadowTop,
|
IconInnerShadowTop,
|
||||||
|
|
@ -11,23 +10,14 @@ import {
|
||||||
IconMessageCircle,
|
IconMessageCircle,
|
||||||
IconChartArea,
|
IconChartArea,
|
||||||
IconCreditCard,
|
IconCreditCard,
|
||||||
|
IconBoxModel
|
||||||
} from "@tabler/icons-react"
|
} from "@tabler/icons-react"
|
||||||
|
|
||||||
import { NavMain } from "@/components/dashboard/nav-main"
|
import { NavMain } from "@/components/dashboard/nav-main"
|
||||||
import { NavSecondary } from "@/components/dashboard/nav-secondary"
|
import { NavSecondary } from "@/components/dashboard/nav-secondary"
|
||||||
import { NavUser } from "@/components/dashboard/nav-user"
|
import { NavUser } from "@/components/dashboard/nav-user"
|
||||||
import { NavDocuments } from "@/components/dashboard/nav-documents"
|
import { NavDocuments } from "@/components/dashboard/nav-documents"
|
||||||
|
|
||||||
import {
|
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar"
|
||||||
Sidebar,
|
|
||||||
SidebarContent,
|
|
||||||
SidebarFooter,
|
|
||||||
SidebarHeader,
|
|
||||||
SidebarMenu,
|
|
||||||
SidebarMenuButton,
|
|
||||||
SidebarMenuItem,
|
|
||||||
} from "@/components/ui/sidebar"
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
user: {
|
user: {
|
||||||
|
|
@ -48,9 +38,14 @@ const data = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Build",
|
title: "Build",
|
||||||
url: "/build",
|
url: "/builds",
|
||||||
icon: IconBuilding
|
icon: IconBuilding
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Build Parts",
|
||||||
|
url: "/build-parts",
|
||||||
|
icon: IconBoxModel
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Build Types",
|
title: "Build Types",
|
||||||
url: "/build-types",
|
url: "/build-types",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
"use client"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
|
import { BuildAreasAdd, buildAreasAddSchema } from "./schema"
|
||||||
|
import { useAddBuildAreasMutation } from "./queries"
|
||||||
|
|
||||||
|
const BuildAreasForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildAreasAdd>({
|
||||||
|
resolver: zodResolver(buildAreasAddSchema),
|
||||||
|
defaultValues: {
|
||||||
|
areaName: "",
|
||||||
|
areaCode: "",
|
||||||
|
areaType: "",
|
||||||
|
areaDirection: "",
|
||||||
|
areaGrossSize: 0,
|
||||||
|
areaNetSize: 0,
|
||||||
|
width: 0,
|
||||||
|
size: 0,
|
||||||
|
expiryStarts: "",
|
||||||
|
expiryEnds: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
|
const mutation = useAddBuildAreasMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildAreasAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
className="space-y-6 p-4"
|
||||||
|
>
|
||||||
|
{/* ROW 1 */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Name</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Name" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaCode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Code</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Code" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaType"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Type</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Type" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaDirection"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Direction</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Direction" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaGrossSize"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Gross Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Gross Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaNetSize"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Net Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Net Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Width</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Width" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="size"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* EXPIRY DATES */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryStarts"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Starts</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryEnds"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Ends</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button type="submit" className="w-full">
|
||||||
|
Add Build Address
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { BuildAreasForm }
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { BuildAreasDataTableAdd } from './table/data-table';
|
||||||
|
import { useGraphQlBuildAreasList } from '@/pages/build-areas/queries';
|
||||||
|
import { BuildAreasForm } from './form';
|
||||||
|
|
||||||
|
const PageAddBuildAreas = () => {
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildAreasDataTableAdd
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildAreasForm refetchTable={refetch} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageAddBuildAreas };
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
import { BuildAreasAdd } from './schema';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildSitesAdd = async (record: BuildAreasAdd): Promise<{ data: BuildAreasAdd | null; status: number }> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
console.dir({ record })
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/build-areas/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, status: res.status }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useAddBuildAreasMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data }: { data: BuildAreasAdd }) => fetchGraphQlBuildSitesAdd(data),
|
||||||
|
onSuccess: () => { console.log("Build areas created successfully") },
|
||||||
|
onError: (error) => { console.error("Add build areas failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildAreasAddSchema = z.object({
|
||||||
|
|
||||||
|
areaName: z.string(),
|
||||||
|
areaCode: z.string(),
|
||||||
|
areaType: z.string(),
|
||||||
|
areaDirection: z.string(),
|
||||||
|
areaGrossSize: z.number(),
|
||||||
|
areaNetSize: z.number(),
|
||||||
|
width: z.number(),
|
||||||
|
size: z.number(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional()
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildAreasAdd = z.infer<typeof buildAreasAddSchema>;
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Drawer, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTrigger } from "@/components/ui/drawer"
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { IconGripVertical } from "@tabler/icons-react"
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
function DragHandle({ id }: { id: number }) {
|
||||||
|
const { attributes, listeners } = useSortable({ id })
|
||||||
|
return (
|
||||||
|
<Button {...attributes} {...listeners} variant="ghost" size="icon" className="text-muted-foreground size-7 hover:bg-transparent">
|
||||||
|
<IconGripVertical className="text-muted-foreground size-3" />
|
||||||
|
<span className="sr-only">Drag to reorder</span>
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaName",
|
||||||
|
header: "Area Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaCode",
|
||||||
|
header: "Area Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaType",
|
||||||
|
header: "Area Type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaDirection",
|
||||||
|
header: "Area Direction",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaGrossSize",
|
||||||
|
header: "Area Gross Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaNetSize",
|
||||||
|
header: "Area Net Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "width",
|
||||||
|
header: "Width",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "size",
|
||||||
|
header: "Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-sites/update?uuid=${row.original.uuid}`) }}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,254 @@
|
||||||
|
"use client"
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||||
|
import { Tabs, TabsContent } from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { Home } from "lucide-react"
|
||||||
|
import { useDeleteBuildSiteMutation } from "@/pages/build-sites/queries"
|
||||||
|
|
||||||
|
export function BuildAreasDataTableAdd({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage,
|
||||||
|
pageSize,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable,
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage: number,
|
||||||
|
pageSize: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeleteBuildSiteMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
enableRowSelection: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
const nextPagination = typeof updater === "function" ? updater(pagination) : updater;
|
||||||
|
onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize);
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-areas") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build Areas</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline"
|
||||||
|
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
||||||
|
>
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
areaName: z.string(),
|
||||||
|
areaCode: z.string(),
|
||||||
|
areaType: z.string(),
|
||||||
|
areaDirection: z.string(),
|
||||||
|
areaGrossSize: z.number(),
|
||||||
|
areaNetSize: z.number(),
|
||||||
|
width: z.number(),
|
||||||
|
size: z.number(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
interface PeopleAdd {
|
||||||
|
|
||||||
|
firstName: string;
|
||||||
|
surname: string;
|
||||||
|
middleName?: string;
|
||||||
|
sexCode: string;
|
||||||
|
personRef?: string;
|
||||||
|
personTag?: string;
|
||||||
|
fatherName?: string;
|
||||||
|
motherName?: string;
|
||||||
|
countryCode: string;
|
||||||
|
nationalIdentityId: string;
|
||||||
|
birthPlace: string;
|
||||||
|
birthDate: string;
|
||||||
|
taxNo?: string;
|
||||||
|
birthname?: string;
|
||||||
|
expiryStarts?: string;
|
||||||
|
expiryEnds?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type { PeopleAdd };
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaName",
|
||||||
|
header: "Area Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaCode",
|
||||||
|
header: "Area Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaType",
|
||||||
|
header: "Area Type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaDirection",
|
||||||
|
header: "Area Direction",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaGrossSize",
|
||||||
|
header: "Area Gross Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaNetSize",
|
||||||
|
header: "Area Net Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "width",
|
||||||
|
header: "Width",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "size",
|
||||||
|
header: "Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-areas/update?uuid=${row.original.uuid}`) }}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,270 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
IconPlus,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import {
|
||||||
|
Tabs,
|
||||||
|
TabsContent,
|
||||||
|
TabsList,
|
||||||
|
TabsTrigger,
|
||||||
|
} from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useDeleteBuildAreaMutation } from "../queries"
|
||||||
|
|
||||||
|
export function BuildAreasDataTable({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage = 1,
|
||||||
|
pageSize = 10,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage?: number,
|
||||||
|
pageSize?: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void,
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeleteBuildAreaMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
enableRowSelection: true,
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => { const nextPagination = typeof updater === "function" ? updater(pagination) : updater; onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize) },
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-areas/add") }}>
|
||||||
|
<IconPlus />
|
||||||
|
<span className="hidden lg:inline">Add Build Areas</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline" className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6">
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
areaName: z.string(),
|
||||||
|
areaCode: z.string(),
|
||||||
|
areaType: z.string(),
|
||||||
|
areaDirection: z.string(),
|
||||||
|
areaGrossSize: z.number(),
|
||||||
|
areaNetSize: z.number(),
|
||||||
|
width: z.number(),
|
||||||
|
size: z.number(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
import { BuildAreasDataTable } from './list/data-table';
|
||||||
|
import { useGraphQlBuildAreasList } from './queries';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
const PageBuildAreas = () => {
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
|
|
||||||
|
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
||||||
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading build areas</div> }
|
||||||
|
|
||||||
|
return <BuildAreasDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { PageBuildAreas };
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client'
|
||||||
|
import { useQuery, useMutation } from '@tanstack/react-query'
|
||||||
|
import { ListArguments } from '@/types/listRequest'
|
||||||
|
|
||||||
|
const fetchGraphQlBuildAreasList = async (params: ListArguments): Promise<any> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
const { limit, skip, sort, filters } = params;
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/build-areas/list', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ limit, skip, sort, filters }) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, totalCount: data.totalCount }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchGraphQlDeleteBuildArea = async (uuid: string): Promise<boolean> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-areas/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return data
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useGraphQlBuildAreasList(params: ListArguments) {
|
||||||
|
return useQuery({ queryKey: ['graphql-build-areas-list', params], queryFn: () => fetchGraphQlBuildAreasList(params) })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDeleteBuildAreaMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteBuildArea(uuid),
|
||||||
|
onSuccess: () => { console.log("Build area deleted successfully") },
|
||||||
|
onError: (error) => { console.error("Delete build area failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
interface BuildSites {
|
||||||
|
|
||||||
|
_id: string;
|
||||||
|
uuid: string;
|
||||||
|
siteName: string;
|
||||||
|
siteNo: string;
|
||||||
|
expiryStarts: string;
|
||||||
|
expiryEnds: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { BuildSites };
|
||||||
|
|
@ -0,0 +1,194 @@
|
||||||
|
"use client"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
|
import { useUpdateBuildSitesMutation } from "@/pages/build-sites/update/queries"
|
||||||
|
import { BuildAreasUpdate, buildAreasUpdateSchema } from "@/pages/build-areas/update/schema"
|
||||||
|
|
||||||
|
const BuildAreasForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildAreasUpdate, selectedUuid: string }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildAreasUpdate>({ resolver: zodResolver(buildAreasUpdateSchema), defaultValues: { ...initData } })
|
||||||
|
|
||||||
|
const { handleSubmit } = form
|
||||||
|
|
||||||
|
const mutation = useUpdateBuildSitesMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildAreasUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
className="space-y-6 p-4"
|
||||||
|
>
|
||||||
|
{/* ROW 1 */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Name</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Name" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaCode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Code</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Code" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaType"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Type</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Type" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaDirection"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Direction</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Direction" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaGrossSize"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Gross Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Gross Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="areaNetSize"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Area Net Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Area Net Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="width"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Width</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Width" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="size"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Size</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Size" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* EXPIRY DATES */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryStarts"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Starts</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryEnds"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Ends</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button type="submit" className="w-full">
|
||||||
|
Add Build Address
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BuildAreasForm }
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { BuildAreasForm } from '@/pages/build-areas/update/form';
|
||||||
|
import { useSearchParams, useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { BuildAreasDataTableUpdate } from './table/data-table';
|
||||||
|
import { useGraphQlBuildAreasList } from '../queries';
|
||||||
|
|
||||||
|
const PageUpdateBuildSites = () => {
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const router = useRouter()
|
||||||
|
const uuid = searchParams?.get('uuid') || null
|
||||||
|
const backToBuildAddress = <>
|
||||||
|
<div>UUID not found in search params</div>
|
||||||
|
<Button onClick={() => router.push('/build-areas')}>Back to Build Areas</Button>
|
||||||
|
</>
|
||||||
|
if (!uuid) { return backToBuildAddress }
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildAreasList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
|
const initData = data?.data?.[0] || null;
|
||||||
|
if (!initData) { return backToBuildAddress }
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildAreasDataTableUpdate
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
||||||
|
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildAreasForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageUpdateBuildSites };
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { UpdateBuildAreasUpdate } from './types';
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildAreasUpdate = async (record: UpdateBuildAreasUpdate, uuid: string): Promise<{ data: UpdateBuildAreasUpdate | null; status: number }> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-areas/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, status: res.status }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useUpdateBuildAreasMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data, uuid }: { data: UpdateBuildAreasUpdate, uuid: string }) => fetchGraphQlBuildAreasUpdate(data, uuid),
|
||||||
|
onSuccess: () => { console.log("Build Areas updated successfully") },
|
||||||
|
onError: (error) => { console.error("Update Build Areas failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildAreasUpdateSchema = z.object({
|
||||||
|
areaName: z.string().optional(),
|
||||||
|
areaCode: z.string().optional(),
|
||||||
|
areaType: z.string().optional(),
|
||||||
|
areaDirection: z.string().optional(),
|
||||||
|
areaGrossSize: z.number().optional(),
|
||||||
|
areaNetSize: z.number().optional(),
|
||||||
|
width: z.number().optional(),
|
||||||
|
size: z.number().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildAreasUpdate = z.infer<typeof buildAreasUpdateSchema>;
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Drawer, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTrigger } from "@/components/ui/drawer"
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { IconGripVertical } from "@tabler/icons-react"
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaName",
|
||||||
|
header: "Area Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaCode",
|
||||||
|
header: "Area Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaType",
|
||||||
|
header: "Area Type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaDirection",
|
||||||
|
header: "Area Direction",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaGrossSize",
|
||||||
|
header: "Area Gross Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "areaNetSize",
|
||||||
|
header: "Area Net Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "width",
|
||||||
|
header: "Width",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "size",
|
||||||
|
header: "Size",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,279 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import {
|
||||||
|
Tabs,
|
||||||
|
TabsContent,
|
||||||
|
TabsList,
|
||||||
|
TabsTrigger,
|
||||||
|
} from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { Home } from "lucide-react"
|
||||||
|
import { useDeletePersonMutation } from "@/pages/people/queries"
|
||||||
|
|
||||||
|
export function BuildAreasDataTableUpdate({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage,
|
||||||
|
pageSize,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable,
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage: number,
|
||||||
|
pageSize: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeletePersonMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
enableRowSelection: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
const nextPagination = typeof updater === "function" ? updater(pagination) : updater;
|
||||||
|
onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize);
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-areas") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build Areas</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline"
|
||||||
|
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
||||||
|
>
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
areaName: z.string(),
|
||||||
|
areaCode: z.string(),
|
||||||
|
areaType: z.string(),
|
||||||
|
areaDirection: z.string(),
|
||||||
|
areaGrossSize: z.number(),
|
||||||
|
areaNetSize: z.number(),
|
||||||
|
width: z.number(),
|
||||||
|
size: z.number(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
interface UpdateBuildAreasUpdate {
|
||||||
|
|
||||||
|
areaName: string;
|
||||||
|
areaCode: string;
|
||||||
|
areaType: string;
|
||||||
|
areaDirection: string;
|
||||||
|
areaGrossSize: number;
|
||||||
|
areaNetSize: number;
|
||||||
|
width: number;
|
||||||
|
size: number;
|
||||||
|
expiryStarts?: string;
|
||||||
|
expiryEnds?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { UpdateBuildAreasUpdate };
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
"use client"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
|
import { BuildIbansAdd, buildIbansAddSchema } from "./schema"
|
||||||
|
import { useAddBuildIbansMutation } from "./queries"
|
||||||
|
|
||||||
|
const BuildIbansForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildIbansAdd>({
|
||||||
|
resolver: zodResolver(buildIbansAddSchema),
|
||||||
|
defaultValues: {
|
||||||
|
iban: "",
|
||||||
|
startDate: "",
|
||||||
|
stopDate: "",
|
||||||
|
bankCode: "",
|
||||||
|
xcomment: "",
|
||||||
|
expiryStarts: "",
|
||||||
|
expiryEnds: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
|
const mutation = useAddBuildIbansMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildIbansAdd) { mutation.mutate({ data: values }); setTimeout(() => refetchTable(), 400) };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
className="space-y-6 p-4"
|
||||||
|
>
|
||||||
|
{/* ROW 1 */}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="iban"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>IBAN</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="IBAN" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="bankCode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Bank Code</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Bank Code" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="startDate"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Start Date</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="stopDate"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Stop Date</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="xcomment"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Comment</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Comment" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* EXPIRY DATES */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryStarts"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Starts</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryEnds"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Ends</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button type="submit" className="w-full">
|
||||||
|
Add Build Address
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { BuildIbansForm }
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { BuildIbansDataTableAdd } from './table/data-table';
|
||||||
|
import { BuildIbansForm } from './form';
|
||||||
|
import { useGraphQlBuildIbansList } from '../queries';
|
||||||
|
|
||||||
|
const PageAddBuildIbans = () => {
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildIbansList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildIbansDataTableAdd
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildIbansForm refetchTable={refetch} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageAddBuildIbans };
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
import { BuildIbansAdd } from './schema';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildIbansAdd = async (record: BuildIbansAdd): Promise<{ data: BuildIbansAdd | null; status: number }> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
record.startDate = toISOIfNotZ(record.startDate);
|
||||||
|
record.stopDate = toISOIfNotZ(record.stopDate);
|
||||||
|
console.dir({ record })
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/build-ibans/add', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, status: res.status }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useAddBuildIbansMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data }: { data: BuildIbansAdd }) => fetchGraphQlBuildIbansAdd(data),
|
||||||
|
onSuccess: () => { console.log("Build IBANs created successfully") },
|
||||||
|
onError: (error) => { console.error("Add build IBANs failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildIbansAddSchema = z.object({
|
||||||
|
|
||||||
|
iban: z.string(),
|
||||||
|
startDate: z.string(),
|
||||||
|
stopDate: z.string(),
|
||||||
|
bankCode: z.string(),
|
||||||
|
xcomment: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildIbansAdd = z.infer<typeof buildIbansAddSchema>;
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Drawer, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTrigger } from "@/components/ui/drawer"
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { IconGripVertical } from "@tabler/icons-react"
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
function DragHandle({ id }: { id: number }) {
|
||||||
|
const { attributes, listeners } = useSortable({ id })
|
||||||
|
return (
|
||||||
|
<Button {...attributes} {...listeners} variant="ghost" size="icon" className="text-muted-foreground size-7 hover:bg-transparent">
|
||||||
|
<IconGripVertical className="text-muted-foreground size-3" />
|
||||||
|
<span className="sr-only">Drag to reorder</span>
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "iban",
|
||||||
|
header: "IBAN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "startDate",
|
||||||
|
header: "Start Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "stopDate",
|
||||||
|
header: "Stop Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "bankCode",
|
||||||
|
header: "Bank Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "xcomment",
|
||||||
|
header: "Comment",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-ibans/update?uuid=${row.original.uuid}`) }}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,254 @@
|
||||||
|
"use client"
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||||
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||||
|
import { Tabs, TabsContent } from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { Home } from "lucide-react"
|
||||||
|
import { useDeleteBuildIbanMutation } from "@/pages/build-ibans/queries"
|
||||||
|
|
||||||
|
export function BuildIbansDataTableAdd({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage,
|
||||||
|
pageSize,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable,
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage: number,
|
||||||
|
pageSize: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeleteBuildIbanMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
enableRowSelection: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
const nextPagination = typeof updater === "function" ? updater(pagination) : updater;
|
||||||
|
onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize);
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-ibans") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build IBANs</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline"
|
||||||
|
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
||||||
|
>
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
iban: z.string(),
|
||||||
|
startDate: z.string(),
|
||||||
|
stopDate: z.string(),
|
||||||
|
bankCode: z.string(),
|
||||||
|
xcomment: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
interface PeopleAdd {
|
||||||
|
|
||||||
|
firstName: string;
|
||||||
|
surname: string;
|
||||||
|
middleName?: string;
|
||||||
|
sexCode: string;
|
||||||
|
personRef?: string;
|
||||||
|
personTag?: string;
|
||||||
|
fatherName?: string;
|
||||||
|
motherName?: string;
|
||||||
|
countryCode: string;
|
||||||
|
nationalIdentityId: string;
|
||||||
|
birthPlace: string;
|
||||||
|
birthDate: string;
|
||||||
|
taxNo?: string;
|
||||||
|
birthname?: string;
|
||||||
|
expiryStarts?: string;
|
||||||
|
expiryEnds?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type { PeopleAdd };
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "iban",
|
||||||
|
header: "IBAN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "startDate",
|
||||||
|
header: "Start Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "stopDate",
|
||||||
|
header: "Stop Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "bankCode",
|
||||||
|
header: "Bank Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "xcomment",
|
||||||
|
header: "Comment",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-amber-400 text-black border-amber-400" variant="outline" size="sm" onClick={() => { router.push(`/build-ibans/update?uuid=${row.original.uuid}`) }}>
|
||||||
|
<Pencil />
|
||||||
|
</Button>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,270 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
IconPlus,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import {
|
||||||
|
Tabs,
|
||||||
|
TabsContent,
|
||||||
|
TabsList,
|
||||||
|
TabsTrigger,
|
||||||
|
} from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { useDeleteBuildIbanMutation } from "@/pages/build-ibans/queries"
|
||||||
|
|
||||||
|
export function BuildIbansDataTable({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage = 1,
|
||||||
|
pageSize = 10,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage?: number,
|
||||||
|
pageSize?: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void,
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeleteBuildIbanMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
enableRowSelection: true,
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => { const nextPagination = typeof updater === "function" ? updater(pagination) : updater; onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize) },
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-ibans/add") }}>
|
||||||
|
<IconPlus />
|
||||||
|
<span className="hidden lg:inline">Add Build Iban</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline" className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6">
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
iban: z.string(),
|
||||||
|
startDate: z.string(),
|
||||||
|
stopDate: z.string(),
|
||||||
|
bankCode: z.string(),
|
||||||
|
xcomment: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
import { BuildIbansDataTable } from './list/data-table';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useGraphQlBuildIbansList } from './queries';
|
||||||
|
|
||||||
|
const PageBuildIbans = () => {
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildIbansList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
const handlePageChange = (newPage: number) => { setPage(newPage) };
|
||||||
|
const handlePageSizeChange = (newSize: number) => { setLimit(newSize); setPage(1) };
|
||||||
|
|
||||||
|
if (isLoading) { return <div className="flex items-center justify-center p-8">Loading...</div> }
|
||||||
|
if (error) { return <div className="flex items-center justify-center p-8 text-red-500">Error loading build areas</div> }
|
||||||
|
|
||||||
|
return <BuildIbansDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { PageBuildIbans };
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client'
|
||||||
|
import { useQuery, useMutation } from '@tanstack/react-query'
|
||||||
|
import { ListArguments } from '@/types/listRequest'
|
||||||
|
|
||||||
|
const fetchGraphQlBuildIbansList = async (params: ListArguments): Promise<any> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
const { limit, skip, sort, filters } = params;
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/build-ibans/list', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ limit, skip, sort, filters }) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, totalCount: data.totalCount }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchGraphQlDeleteBuildIban = async (uuid: string): Promise<boolean> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-ibans/delete?uuid=${uuid}`, { method: 'GET', cache: 'no-store', credentials: "include" });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return data
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useGraphQlBuildIbansList(params: ListArguments) {
|
||||||
|
return useQuery({ queryKey: ['graphql-build-ibans-list', params], queryFn: () => fetchGraphQlBuildIbansList(params) })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDeleteBuildIbanMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteBuildIban(uuid),
|
||||||
|
onSuccess: () => { console.log("Build iban deleted successfully") },
|
||||||
|
onError: (error) => { console.error("Delete build iban failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
interface BuildSites {
|
||||||
|
|
||||||
|
_id: string;
|
||||||
|
uuid: string;
|
||||||
|
siteName: string;
|
||||||
|
siteNo: string;
|
||||||
|
expiryStarts: string;
|
||||||
|
expiryEnds: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { BuildSites };
|
||||||
|
|
@ -0,0 +1,147 @@
|
||||||
|
"use client"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { DateTimePicker } from "@/components/ui/date-time-picker"
|
||||||
|
import { useUpdateBuildIbansMutation } from "@/pages/build-ibans/update/queries"
|
||||||
|
import { BuildIbansUpdate, buildIbansUpdateSchema } from "@/pages/build-ibans/update/schema"
|
||||||
|
|
||||||
|
const BuildIbansForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildIbansUpdate, selectedUuid: string }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildIbansUpdate>({ resolver: zodResolver(buildIbansUpdateSchema), defaultValues: { ...initData } })
|
||||||
|
|
||||||
|
const { handleSubmit } = form
|
||||||
|
|
||||||
|
const mutation = useUpdateBuildIbansMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildIbansUpdate) { mutation.mutate({ data: values as any || initData, uuid: selectedUuid }); setTimeout(() => refetchTable(), 400) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
||||||
|
|
||||||
|
{/* ROW 1 */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="iban"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>IBAN</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="IBAN" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="bankCode"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Bank Code</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Bank Code" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="startDate"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Start Date</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="stopDate"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Stop Date</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="xcomment"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Comment</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="Comment" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* EXPIRY DATES */}
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryStarts"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Starts</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="expiryEnds"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Expiry Ends</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<DateTimePicker {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button type="submit" className="w-full">
|
||||||
|
Update Build IBAN
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BuildIbansForm }
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { BuildIbansForm } from '@/pages/build-ibans/update/form';
|
||||||
|
import { useSearchParams, useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { BuildIbansDataTableUpdate } from './table/data-table';
|
||||||
|
import { useGraphQlBuildIbansList } from '../queries';
|
||||||
|
|
||||||
|
const PageUpdateBuildIbans = () => {
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [limit, setLimit] = useState(10);
|
||||||
|
const [sort, setSort] = useState({ createdAt: 'desc' });
|
||||||
|
const [filters, setFilters] = useState({});
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const router = useRouter()
|
||||||
|
const uuid = searchParams?.get('uuid') || null
|
||||||
|
const backToBuildAddress = <>
|
||||||
|
<div>UUID not found in search params</div>
|
||||||
|
<Button onClick={() => router.push('/build-ibans')}>Back to Build IBANs</Button>
|
||||||
|
</>
|
||||||
|
if (!uuid) { return backToBuildAddress }
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildIbansList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
|
const initData = data?.data?.[0] || null;
|
||||||
|
if (!initData) { return backToBuildAddress }
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildIbansDataTableUpdate
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
||||||
|
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildIbansForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageUpdateBuildIbans };
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { UpdateBuildIbansUpdate } from './types';
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildIbansUpdate = async (record: UpdateBuildIbansUpdate, uuid: string): Promise<{ data: UpdateBuildIbansUpdate | null; status: number }> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
record.expiryStarts = record.expiryStarts ? toISOIfNotZ(record.expiryStarts) : undefined;
|
||||||
|
record.expiryEnds = record.expiryEnds ? toISOIfNotZ(record.expiryEnds) : undefined;
|
||||||
|
record.startDate = toISOIfNotZ(record.startDate);
|
||||||
|
record.stopDate = toISOIfNotZ(record.stopDate);
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-ibans/update?uuid=${uuid || ''}`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify(record) });
|
||||||
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }
|
||||||
|
const data = await res.json();
|
||||||
|
return { data: data.data, status: res.status }
|
||||||
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
||||||
|
};
|
||||||
|
|
||||||
|
export function useUpdateBuildIbansMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data, uuid }: { data: UpdateBuildIbansUpdate, uuid: string }) => fetchGraphQlBuildIbansUpdate(data, uuid),
|
||||||
|
onSuccess: () => { console.log("Build IBANs updated successfully") },
|
||||||
|
onError: (error) => { console.error("Update Build IBANs failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildIbansUpdateSchema = z.object({
|
||||||
|
|
||||||
|
iban: z.string(),
|
||||||
|
startDate: z.string(),
|
||||||
|
stopDate: z.string(),
|
||||||
|
bankCode: z.string(),
|
||||||
|
xcomment: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildIbansUpdate = z.infer<typeof buildIbansUpdateSchema>;
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
"use client"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Drawer, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTrigger } from "@/components/ui/drawer"
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import { useSortable } from "@dnd-kit/sortable"
|
||||||
|
import { IconGripVertical } from "@tabler/icons-react"
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { ColumnDef, flexRender, Row } from "@tanstack/react-table"
|
||||||
|
import { TableCell, TableRow } from "@/components/ui/table"
|
||||||
|
import { CSS } from "@dnd-kit/utilities"
|
||||||
|
import { schema, schemaType } from "./schema"
|
||||||
|
import { dateToLocaleString } from "@/lib/utils"
|
||||||
|
import { Pencil, Trash } from "lucide-react"
|
||||||
|
|
||||||
|
export function DraggableRow({ row }: { row: Row<z.infer<typeof schema>> }) {
|
||||||
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
||||||
|
return (
|
||||||
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
||||||
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
||||||
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
||||||
|
>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumns(router: any, deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "iban",
|
||||||
|
header: "IBAN",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "startDate",
|
||||||
|
header: "Start Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "stopDate",
|
||||||
|
header: "Stop Date",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "bankCode",
|
||||||
|
header: "Bank Code",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "xcomment",
|
||||||
|
header: "Comment",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: "Created",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "updatedAt",
|
||||||
|
header: "Updated",
|
||||||
|
cell: ({ getValue }) => dateToLocaleString(getValue() as string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryStarts",
|
||||||
|
header: "Expiry Starts",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "expiryEnds",
|
||||||
|
header: "Expiry Ends",
|
||||||
|
cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "Actions",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
||||||
|
<Trash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getColumns };
|
||||||
|
|
@ -0,0 +1,279 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
closestCenter,
|
||||||
|
DndContext,
|
||||||
|
KeyboardSensor,
|
||||||
|
MouseSensor,
|
||||||
|
TouchSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
type UniqueIdentifier,
|
||||||
|
} from "@dnd-kit/core"
|
||||||
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers"
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from "@dnd-kit/sortable"
|
||||||
|
import {
|
||||||
|
IconChevronDown,
|
||||||
|
IconChevronLeft,
|
||||||
|
IconChevronRight,
|
||||||
|
IconChevronsLeft,
|
||||||
|
IconChevronsRight,
|
||||||
|
IconLayoutColumns,
|
||||||
|
} from "@tabler/icons-react"
|
||||||
|
import {
|
||||||
|
ColumnFiltersState,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFacetedRowModel,
|
||||||
|
getFacetedUniqueValues,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
SortingState,
|
||||||
|
useReactTable,
|
||||||
|
VisibilityState,
|
||||||
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { Label } from "@/components/ui/label"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table"
|
||||||
|
import {
|
||||||
|
Tabs,
|
||||||
|
TabsContent,
|
||||||
|
TabsList,
|
||||||
|
TabsTrigger,
|
||||||
|
} from "@/components/ui/tabs"
|
||||||
|
import { schemaType } from "./schema"
|
||||||
|
import { getColumns, DraggableRow } from "./columns"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
import { Home } from "lucide-react"
|
||||||
|
import { useDeletePersonMutation } from "@/pages/people/queries"
|
||||||
|
|
||||||
|
export function BuildIbansDataTableUpdate({
|
||||||
|
data,
|
||||||
|
totalCount,
|
||||||
|
currentPage,
|
||||||
|
pageSize,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
|
refetchTable,
|
||||||
|
}: {
|
||||||
|
data: schemaType[],
|
||||||
|
totalCount: number,
|
||||||
|
currentPage: number,
|
||||||
|
pageSize: number,
|
||||||
|
onPageChange: (page: number) => void,
|
||||||
|
onPageSizeChange: (size: number) => void,
|
||||||
|
refetchTable: () => void
|
||||||
|
}) {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [rowSelection, setRowSelection] = React.useState({})
|
||||||
|
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||||
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
||||||
|
const [sorting, setSorting] = React.useState<SortingState>([])
|
||||||
|
const sortableId = React.useId()
|
||||||
|
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}))
|
||||||
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
|
const deleteMutation = useDeletePersonMutation()
|
||||||
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
||||||
|
const columns = getColumns(router, deleteHandler);
|
||||||
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
pageCount: totalPages,
|
||||||
|
state: { sorting, columnVisibility, rowSelection, columnFilters, pagination },
|
||||||
|
manualPagination: true,
|
||||||
|
enableRowSelection: true,
|
||||||
|
getRowId: (row) => row._id.toString(),
|
||||||
|
onRowSelectionChange: setRowSelection,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
|
onPaginationChange: (updater) => {
|
||||||
|
const nextPagination = typeof updater === "function" ? updater(pagination) : updater;
|
||||||
|
onPageChange(nextPagination.pageIndex + 1); onPageSizeChange(nextPagination.pageSize);
|
||||||
|
},
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
getFacetedRowModel: getFacetedRowModel(),
|
||||||
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: string) => { const newSize = Number(value); onPageSizeChange(newSize); onPageChange(1) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs defaultValue="outline" className="w-full flex-col justify-start gap-6">
|
||||||
|
<div className="flex items-center justify-between px-4 lg:px-6">
|
||||||
|
<Label htmlFor="view-selector" className="sr-only">
|
||||||
|
View
|
||||||
|
</Label>
|
||||||
|
<Select defaultValue="outline">
|
||||||
|
<SelectTrigger className="flex w-fit @4xl/main:hidden" size="sm" id="view-selector">
|
||||||
|
<SelectValue placeholder="Select a view" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="outline">Outline</SelectItem>
|
||||||
|
<SelectItem value="past-performance">Past Performance</SelectItem>
|
||||||
|
<SelectItem value="key-personnel">Key Personnel</SelectItem>
|
||||||
|
<SelectItem value="focus-documents">Focus Documents</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm">
|
||||||
|
<IconLayoutColumns />
|
||||||
|
<span className="hidden lg:inline">Customize Columns</span>
|
||||||
|
<span className="lg:hidden">Columns</span>
|
||||||
|
<IconChevronDown />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
|
{table.getAllColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide()).map((column) => {
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem key={column.id} className="capitalize" checked={column.getIsVisible()} onCheckedChange={(value) => column.toggleVisibility(!!value)} >
|
||||||
|
{column.id}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-ibans") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build Areas</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<TabsContent value="outline"
|
||||||
|
className="relative flex flex-col gap-4 overflow-auto px-4 lg:px-6"
|
||||||
|
>
|
||||||
|
<div className="overflow-hidden rounded-lg border">
|
||||||
|
<DndContext collisionDetection={closestCenter} modifiers={[restrictToVerticalAxis]} sensors={sensors} id={sortableId} >
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-muted sticky top-0 z-10">
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<TableRow key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
return (
|
||||||
|
<TableHead key={header.id} colSpan={header.colSpan}>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody className="**:data-[slot=table-cell]:first:w-8">
|
||||||
|
{table.getRowModel().rows?.length ? (<SortableContext items={dataIds} strategy={verticalListSortingStrategy} >
|
||||||
|
{table.getRowModel().rows.map((row) => <DraggableRow key={row.id} row={row} />)}
|
||||||
|
</SortableContext>) : (
|
||||||
|
<TableRow><TableCell colSpan={columns.length} className="h-24 text-center">No results.</TableCell></TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</DndContext>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between px-4">
|
||||||
|
<div className="text-muted-foreground hidden flex-1 text-sm lg:flex">
|
||||||
|
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
||||||
|
{table.getFilteredRowModel().rows.length} row(s) selected.
|
||||||
|
</div>
|
||||||
|
<div className="flex w-full items-center gap-8 lg:w-fit">
|
||||||
|
<div className="hidden items-center gap-2 lg:flex">
|
||||||
|
<Label htmlFor="rows-per-page" className="text-sm font-medium">Rows per page</Label>
|
||||||
|
<Select value={`${pageSize}`} onValueChange={handlePageSizeChange}>
|
||||||
|
<SelectTrigger size="sm" className="w-20" id="rows-per-page">
|
||||||
|
<SelectValue placeholder={pageSize} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent side="top">
|
||||||
|
{[10, 20, 30].map((size) => <SelectItem key={size} value={`${size}`}>{size}</SelectItem>)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Page {currentPage} of {totalPages}
|
||||||
|
</div>
|
||||||
|
<div className="flex w-fit items-center justify-center text-sm font-medium">
|
||||||
|
Total Count: {totalCount}
|
||||||
|
</div>
|
||||||
|
<div className="ml-auto flex items-center gap-2 lg:ml-0">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onPageChange(totalPages)}
|
||||||
|
disabled={currentPage >= totalPages}
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="past-performance" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="key-personnel" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="focus-documents" className="flex flex-col px-4 lg:px-6">
|
||||||
|
<div className="aspect-video w-full flex-1 rounded-lg border border-dashed"></div>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
iban: z.string(),
|
||||||
|
startDate: z.string(),
|
||||||
|
stopDate: z.string(),
|
||||||
|
bankCode: z.string(),
|
||||||
|
xcomment: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
createdAt: z.string(),
|
||||||
|
updatedAt: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
interface UpdateBuildIbansUpdate {
|
||||||
|
|
||||||
|
iban: string;
|
||||||
|
startDate: string;
|
||||||
|
stopDate: string;
|
||||||
|
bankCode: string;
|
||||||
|
xcomment: string;
|
||||||
|
expiryStarts?: string;
|
||||||
|
expiryEnds?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { UpdateBuildIbansUpdate };
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use client';
|
'use client';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useGraphQlBuildSitesList } from '@/pages/build-sites/queries';
|
import { useGraphQlBuildSitesList } from '@/pages/build-sites/queries';
|
||||||
import { BuildAddressDataTableUpdate } from '@/pages/build-sites/update/table/data-table';
|
import { BuildSitesDataTableUpdate } from '@/pages/build-sites/update/table/data-table';
|
||||||
import { BuildAddressForm } from '@/pages/build-sites/update/form';
|
import { BuildAddressForm } from '@/pages/build-sites/update/form';
|
||||||
import { useSearchParams, useRouter } from 'next/navigation'
|
import { useSearchParams, useRouter } from 'next/navigation'
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
@ -24,7 +24,7 @@ const PageUpdateBuildSites = () => {
|
||||||
if (!initData) { return backToBuildAddress }
|
if (!initData) { return backToBuildAddress }
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BuildAddressDataTableUpdate
|
<BuildSitesDataTableUpdate
|
||||||
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
||||||
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ import { useRouter } from "next/navigation"
|
||||||
import { Home } from "lucide-react"
|
import { Home } from "lucide-react"
|
||||||
import { useDeletePersonMutation } from "@/pages/people/queries"
|
import { useDeletePersonMutation } from "@/pages/people/queries"
|
||||||
|
|
||||||
export function BuildAddressDataTableUpdate({
|
export function BuildSitesDataTableUpdate({
|
||||||
data,
|
data,
|
||||||
totalCount,
|
totalCount,
|
||||||
currentPage,
|
currentPage,
|
||||||
|
|
@ -167,9 +167,9 @@ export function BuildAddressDataTableUpdate({
|
||||||
})}
|
})}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<Button variant="outline" size="sm" onClick={() => { router.push("/build-sites") }}>
|
<Button variant="outline" size="sm" onClick={() => { router.push("/build-areas") }}>
|
||||||
<Home />
|
<Home />
|
||||||
<span className="hidden lg:inline">Back to Build Sites</span>
|
<span className="hidden lg:inline">Back to Build Areas</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue