updated build-sites
This commit is contained in:
parent
688576a1de
commit
44f209ae1f
|
|
@ -12,6 +12,8 @@ import { BuildAreaModule } from './build-area/build-area.module';
|
||||||
import { UserTypesModule } from './user-types/user-types.module';
|
import { UserTypesModule } from './user-types/user-types.module';
|
||||||
import { BuildTypesModule } from './build-types/build-types.module';
|
import { BuildTypesModule } from './build-types/build-types.module';
|
||||||
import { BuildAddressModule } from './build-address/build-address.module';
|
import { BuildAddressModule } from './build-address/build-address.module';
|
||||||
|
import { BuildIbanModule } from './build-iban/build-iban.module';
|
||||||
|
import { BuildSitesModule } from './build-sites/build-sites.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -29,6 +31,8 @@ import { BuildAddressModule } from './build-address/build-address.module';
|
||||||
UserTypesModule,
|
UserTypesModule,
|
||||||
BuildTypesModule,
|
BuildTypesModule,
|
||||||
BuildAddressModule,
|
BuildAddressModule,
|
||||||
|
BuildIbanModule,
|
||||||
|
BuildSitesModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
import { BuildArea } from '@/models/build-area.model';
|
import { BuildArea } from '@/models/build-area.model';
|
||||||
|
import { BuildAreaService } from './build-area.service';
|
||||||
|
import { ListArguments } from '@/dto/list.input';
|
||||||
|
import { UpdateBuildAreaInput } from './dto/update-build-area.input';
|
||||||
|
import { ListBuildAreaResponse } from './dto/list-build-area.response';
|
||||||
import { CreateBuildAreaInput } from './dto/create-build-area.input';
|
import { CreateBuildAreaInput } from './dto/create-build-area.input';
|
||||||
import graphqlFields from 'graphql-fields';
|
import graphqlFields from 'graphql-fields';
|
||||||
import { BuildAreaService } from './build-area.service';
|
|
||||||
import type { GraphQLResolveInfo } from 'graphql';
|
import type { GraphQLResolveInfo } from 'graphql';
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
|
|
@ -11,18 +14,23 @@ export class BuildAreaResolver {
|
||||||
|
|
||||||
constructor(private readonly buildAreaService: BuildAreaService) { }
|
constructor(private readonly buildAreaService: BuildAreaService) { }
|
||||||
|
|
||||||
@Query(() => [BuildArea], { name: 'BuildAreas' })
|
@Query(() => ListBuildAreaResponse, { name: 'buildAreas' })
|
||||||
async getBuildAreas(@Info() info: GraphQLResolveInfo): Promise<BuildArea[]> {
|
async getBuildAreas(@Info() info: GraphQLResolveInfo, @Args('input') input: ListArguments): Promise<ListBuildAreaResponse> {
|
||||||
const fields = graphqlFields(info); const projection = this.buildAreaService.buildProjection(fields); return this.buildAreaService.findAll(projection);
|
const fields = graphqlFields(info); const projection = this.buildAreaService.buildProjection(fields?.data); return await this.buildAreaService.findAll(projection, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => BuildArea, { name: 'BuildArea', nullable: true })
|
@Query(() => BuildArea, { name: 'getBuildArea', nullable: true })
|
||||||
async getBuildArea(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<BuildArea | null> {
|
async getBuildArea(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<BuildArea | null> {
|
||||||
const fields = graphqlFields(info); const projection = this.buildAreaService.buildProjection(fields); return this.buildAreaService.findById(new Types.ObjectId(id), projection);
|
const fields = graphqlFields(info); const projection = this.buildAreaService.buildProjection(fields); return this.buildAreaService.findById(new Types.ObjectId(id), projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => BuildArea, { name: 'createBuildArea' })
|
@Mutation(() => BuildArea, { name: 'createBuildArea' })
|
||||||
async createBuildArea(@Args('input') input: CreateBuildAreaInput): Promise<BuildArea> {
|
async createBuildArea(@Args('input') input: CreateBuildAreaInput): Promise<BuildArea> { return this.buildAreaService.create(input) }
|
||||||
return this.buildAreaService.create(input);
|
|
||||||
}
|
@Mutation(() => BuildArea, { name: 'updateBuildArea' })
|
||||||
|
async updateBuildArea(@Args('uuid') uuid: string, @Args('input') input: UpdateBuildAreaInput): Promise<BuildArea> { return this.buildAreaService.update(uuid, input) }
|
||||||
|
|
||||||
|
@Mutation(() => Boolean, { name: 'deleteBuildArea' })
|
||||||
|
async deleteBuildArea(@Args('uuid') uuid: string): Promise<boolean> { return this.buildAreaService.delete(uuid) }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,31 +3,39 @@ import { InjectModel } from '@nestjs/mongoose';
|
||||||
import { Types, Model } from 'mongoose';
|
import { Types, Model } from 'mongoose';
|
||||||
import { BuildArea, BuildAreaDocument } from '@/models/build-area.model';
|
import { BuildArea, BuildAreaDocument } from '@/models/build-area.model';
|
||||||
import { CreateBuildAreaInput } from './dto/create-build-area.input';
|
import { CreateBuildAreaInput } from './dto/create-build-area.input';
|
||||||
|
import { ListBuildAreaResponse } from './dto/list-build-area.response';
|
||||||
|
import { UpdateBuildAreaInput } from './dto/update-build-area.input';
|
||||||
|
import { ListArguments } from '@/dto/list.input';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BuildAreaService {
|
export class BuildAreaService {
|
||||||
|
|
||||||
constructor(@InjectModel(BuildArea.name) private readonly buildAreaModel: Model<BuildAreaDocument>) { }
|
constructor(@InjectModel(BuildArea.name) private readonly buildAreaModel: Model<BuildAreaDocument>) { }
|
||||||
|
|
||||||
async findAll(projection?: any): Promise<BuildAreaDocument[]> {
|
async findAll(projection: any, listArguments: ListArguments): Promise<ListBuildAreaResponse> {
|
||||||
return this.buildAreaModel.find({}, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
const { skip, limit, sort, filters } = listArguments;
|
||||||
|
const query: any = {}; if (filters && Object.keys(filters).length > 0) { Object.assign(query, filters) };
|
||||||
|
const totalCount = await this.buildAreaModel.countDocuments(query).exec();
|
||||||
|
const data = await this.buildAreaModel.find(query, projection, { lean: true }).skip(skip).limit(limit).sort(sort).exec();
|
||||||
|
return { data, totalCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
async findById(id: Types.ObjectId, projection?: any): Promise<BuildAreaDocument | null> {
|
async findById(id: Types.ObjectId, projection?: any): Promise<BuildAreaDocument | null> {
|
||||||
return this.buildAreaModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
return this.buildAreaModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(input: CreateBuildAreaInput): Promise<BuildAreaDocument> {
|
async create(input: CreateBuildAreaInput): Promise<BuildAreaDocument> { const buildArea = new this.buildAreaModel(input); return buildArea.save() }
|
||||||
const buildArea = new this.buildAreaModel(input);
|
|
||||||
return buildArea.save();
|
async update(uuid: string, input: UpdateBuildAreaInput): Promise<BuildAreaDocument> { const buildArea = await this.buildAreaModel.findOne({ uuid }); if (!buildArea) { throw new Error('BuildArea not found') }; buildArea.set(input); return buildArea.save() }
|
||||||
}
|
|
||||||
|
async delete(uuid: string): Promise<boolean> { const buildArea = await this.buildAreaModel.deleteMany({ uuid }); return buildArea.deletedCount > 0 }
|
||||||
|
|
||||||
buildProjection(fields: Record<string, any>): any {
|
buildProjection(fields: Record<string, any>): any {
|
||||||
const projection: any = {};
|
const projection: any = {};
|
||||||
for (const key in fields) {
|
for (const key in fields) {
|
||||||
if (key === 'buildArea' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildArea.${subField}`] = 1 } }
|
if (key === 'buildArea' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildArea.${subField}`] = 1 } }
|
||||||
else { projection[key] = 1 }
|
else { projection[key] = 1 }
|
||||||
|
}; return projection;
|
||||||
}
|
}
|
||||||
return projection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,37 @@
|
||||||
import { InputType, Field } from "@nestjs/graphql";
|
import { InputType, Field, ID, Float } from "@nestjs/graphql";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class CreateBuildAreaInput {
|
export class CreateBuildAreaInput {
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
build?: Types.ObjectId;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
partType?: Types.ObjectId;
|
||||||
|
|
||||||
|
@Field(() => Float)
|
||||||
|
areaName: string;
|
||||||
|
|
||||||
|
@Field(() => Float)
|
||||||
|
areaCode: string;
|
||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
uuid: string;
|
areaType: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
areaDirection: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
areaGrossSize: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
areaNetSize: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
width: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
size: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { ObjectType, Field, Int } from "@nestjs/graphql";
|
||||||
|
import { BuildArea } from "@/models/build-area.model";
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class ListBuildAreaResponse {
|
||||||
|
|
||||||
|
@Field(() => [BuildArea], { nullable: true })
|
||||||
|
data?: BuildArea[];
|
||||||
|
|
||||||
|
@Field(() => Int, { nullable: true })
|
||||||
|
totalCount?: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { InputType, Field, Float, ID } from "@nestjs/graphql";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateBuildAreaInput {
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
build?: Types.ObjectId;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
partType?: Types.ObjectId;
|
||||||
|
|
||||||
|
@Field(() => Float, { nullable: true })
|
||||||
|
areaName?: string;
|
||||||
|
|
||||||
|
@Field(() => Float, { nullable: true })
|
||||||
|
areaCode?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
areaType?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
areaDirection?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
areaGrossSize?: number;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
areaNetSize?: number;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
width?: number;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
size?: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { BuildIbanResolver } from './build-iban.resolver';
|
||||||
|
import { BuildIbanService } from './build-iban.service';
|
||||||
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
import { BuildIban, BuildIbanSchema } from '@/models/build.model';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [MongooseModule.forFeature([{ name: BuildIban.name, schema: BuildIbanSchema }])],
|
||||||
|
providers: [BuildIbanResolver, BuildIbanService]
|
||||||
|
})
|
||||||
|
export class BuildIbanModule { }
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||||
|
import { BuildIban } from '@/models/build.model';
|
||||||
|
import graphqlFields from 'graphql-fields';
|
||||||
|
import { Types } from 'mongoose';
|
||||||
|
import { CreateBuildIbanInput } from './dto/create-build-ibans.input';
|
||||||
|
import { UpdateBuildIbanInput } from './dto/update-build-ibans.input';
|
||||||
|
import { ListBuildIbanResponse } from './dto/list-build-ibans.response';
|
||||||
|
import { ListArguments } from '@/dto/list.input';
|
||||||
|
import { BuildIbanService } from './build-iban.service';
|
||||||
|
import type { GraphQLResolveInfo } from 'graphql';
|
||||||
|
|
||||||
|
@Resolver()
|
||||||
|
export class BuildIbanResolver {
|
||||||
|
|
||||||
|
constructor(private readonly buildIbanService: BuildIbanService) { }
|
||||||
|
|
||||||
|
@Query(() => ListBuildIbanResponse, { name: 'buildIbans' })
|
||||||
|
async getBuildIbans(@Info() info: GraphQLResolveInfo, @Args('input') input: ListArguments): Promise<ListBuildIbanResponse> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildIbanService.buildProjection(fields?.data); const { skip, limit, sort, filters } = input;
|
||||||
|
return await this.buildIbanService.findAll(projection, skip, limit, sort, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => BuildIban, { name: 'getBuildIban', nullable: true })
|
||||||
|
async getBuildIban(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<BuildIban | null> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildIbanService.buildProjection(fields); return this.buildIbanService.findById(new Types.ObjectId(id), projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mutation(() => BuildIban, { name: 'createBuildIban' })
|
||||||
|
async createBuildIban(@Args('input') input: CreateBuildIbanInput): Promise<BuildIban> { return this.buildIbanService.create(input) }
|
||||||
|
|
||||||
|
@Mutation(() => BuildIban, { name: 'updateBuildIban' })
|
||||||
|
async updateBuildIban(@Args('uuid') uuid: string, @Args('input') input: UpdateBuildIbanInput): Promise<BuildIban> { return this.buildIbanService.update(uuid, input) }
|
||||||
|
|
||||||
|
@Mutation(() => Boolean, { name: 'deleteBuildIban' })
|
||||||
|
async deleteBuildIban(@Args('uuid') uuid: string): Promise<boolean> { return this.buildIbanService.delete(uuid) }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { Types, Model } from 'mongoose';
|
||||||
|
import { BuildIban, BuildIbanDocument } from '@/models/build.model';
|
||||||
|
import { ListBuildIbanResponse } from './dto/list-build-ibans.response';
|
||||||
|
import { CreateBuildIbanInput } from './dto/create-build-ibans.input';
|
||||||
|
import { UpdateBuildIbanInput } from './dto/update-build-ibans.input';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BuildIbanService {
|
||||||
|
|
||||||
|
constructor(@InjectModel(BuildIban.name) private readonly buildIbanModel: Model<BuildIbanDocument>) { }
|
||||||
|
|
||||||
|
async findAll(projection: any, skip: number, limit: number, sort?: Record<string, 1 | -1>, filters?: Record<string, any>): Promise<ListBuildIbanResponse> {
|
||||||
|
const query: any = {}; if (filters && Object.keys(filters).length > 0) { Object.assign(query, filters) };
|
||||||
|
const totalCount = await this.buildIbanModel.countDocuments(query).exec();
|
||||||
|
const data = await this.buildIbanModel.find(query, projection, { lean: true }).skip(skip).limit(limit).sort(sort).exec();
|
||||||
|
return { data, totalCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
async findById(id: Types.ObjectId, projection?: any): Promise<BuildIbanDocument | null> {
|
||||||
|
return this.buildIbanModel.findById(id, projection, { lean: false }).populate({ path: 'buildIban', select: projection?.buildIban }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(input: CreateBuildIbanInput): Promise<BuildIbanDocument> { const buildIban = new this.buildIbanModel(input); return buildIban.save() }
|
||||||
|
|
||||||
|
async update(uuid: string, input: UpdateBuildIbanInput): Promise<BuildIbanDocument> { const buildIban = await this.buildIbanModel.findOne({ uuid }); if (!buildIban) { throw new Error('BuildIban not found') }; buildIban.set(input); return buildIban.save() }
|
||||||
|
|
||||||
|
async delete(uuid: string): Promise<boolean> { const buildIban = await this.buildIbanModel.deleteMany({ uuid }); return buildIban.deletedCount > 0 }
|
||||||
|
|
||||||
|
buildProjection(fields: Record<string, any>): any {
|
||||||
|
const projection: any = {};
|
||||||
|
for (const key in fields) {
|
||||||
|
if (key === 'buildIban' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildIban.${subField}`] = 1 } }
|
||||||
|
else { projection[key] = 1 }
|
||||||
|
}; return projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { ExpiryBaseInput } from "@/models/base.model";
|
||||||
|
import { InputType, Field } from "@nestjs/graphql";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class CreateBuildIbanInput extends ExpiryBaseInput {
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
iban: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
startDate: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
stopDate: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
bankCode: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
xcomment: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { BuildIban } from "@/models/build.model";
|
||||||
|
import { Field, Int, ObjectType } from "@nestjs/graphql";
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class ListBuildIbanResponse {
|
||||||
|
|
||||||
|
@Field(() => [BuildIban], { nullable: true })
|
||||||
|
data?: BuildIban[];
|
||||||
|
|
||||||
|
@Field(() => Int, { nullable: true })
|
||||||
|
totalCount?: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { InputType, Field } from "@nestjs/graphql";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateBuildIbanInput {
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
iban?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
startDate?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
stopDate?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
bankCode?: string;
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
xcomment?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { BuildSitesService } from './build-sites.service';
|
||||||
|
import { BuildSitesResolver } from './build-sites.resolver';
|
||||||
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
import { BuildSites, BuildSiteSchema } from '@/models/build-site.model';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [MongooseModule.forFeature([{ name: BuildSites.name, schema: BuildSiteSchema }])],
|
||||||
|
providers: [BuildSitesService, BuildSitesResolver]
|
||||||
|
})
|
||||||
|
export class BuildSitesModule { }
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { BuildSitesResolver } from './build-sites.resolver';
|
||||||
|
|
||||||
|
describe('BuildSitesResolver', () => {
|
||||||
|
let resolver: BuildSitesResolver;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [BuildSitesResolver],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
resolver = module.get<BuildSitesResolver>(BuildSitesResolver);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(resolver).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||||
|
import { Types } from 'mongoose';
|
||||||
|
import { BuildSites } from '@/models/build-site.model';
|
||||||
|
import { BuildSitesService } from './build-sites.service';
|
||||||
|
import { ListArguments } from '@/dto/list.input';
|
||||||
|
import { ListBuildSitesResponse } from './dto/list-build-sites.response';
|
||||||
|
import { CreateBuildSitesInput } from './dto/create-build-sites.input';
|
||||||
|
import { UpdateBuildSitesInput } from './dto/update-build-sites.input';
|
||||||
|
import graphqlFields from 'graphql-fields';
|
||||||
|
import type { GraphQLResolveInfo } from 'graphql';
|
||||||
|
|
||||||
|
@Resolver()
|
||||||
|
export class BuildSitesResolver {
|
||||||
|
|
||||||
|
constructor(private readonly buildSitesService: BuildSitesService) { }
|
||||||
|
|
||||||
|
@Query(() => ListBuildSitesResponse, { name: 'buildSites' })
|
||||||
|
async getBuildSites(@Info() info: GraphQLResolveInfo, @Args('input') input: ListArguments): Promise<ListBuildSitesResponse> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildSitesService.buildProjection(fields?.data); const { skip, limit, sort, filters } = input;
|
||||||
|
return await this.buildSitesService.findAll(projection, skip, limit, sort, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query(() => BuildSites, { name: 'getBuildSite', nullable: true })
|
||||||
|
async getBuildSite(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<BuildSites | null> {
|
||||||
|
const fields = graphqlFields(info); const projection = this.buildSitesService.buildProjection(fields); return this.buildSitesService.findById(new Types.ObjectId(id), projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mutation(() => BuildSites, { name: 'createBuildSite' })
|
||||||
|
async createBuildSite(@Args('input') input: CreateBuildSitesInput): Promise<BuildSites> { return this.buildSitesService.create(input) }
|
||||||
|
|
||||||
|
@Mutation(() => BuildSites, { name: 'updateBuildSite' })
|
||||||
|
async updateBuildSite(@Args('uuid') uuid: string, @Args('input') input: UpdateBuildSitesInput): Promise<BuildSites> { return this.buildSitesService.update(uuid, input) }
|
||||||
|
|
||||||
|
@Mutation(() => Boolean, { name: 'deleteBuildSite' })
|
||||||
|
async deleteBuildSite(@Args('uuid') uuid: string): Promise<boolean> { return this.buildSitesService.delete(uuid) }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { BuildSitesService } from './build-sites.service';
|
||||||
|
|
||||||
|
describe('BuildSitesService', () => {
|
||||||
|
let service: BuildSitesService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [BuildSitesService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<BuildSitesService>(BuildSitesService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Types } from 'mongoose';
|
||||||
|
import { ListBuildSitesResponse } from './dto/list-build-sites.response';
|
||||||
|
import { CreateBuildSitesInput } from './dto/create-build-sites.input';
|
||||||
|
import { UpdateBuildSitesInput } from './dto/update-build-sites.input';
|
||||||
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { BuildSites, BuildSiteDocument } from '@/models/build-site.model';
|
||||||
|
import { Model } from 'mongoose';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BuildSitesService {
|
||||||
|
|
||||||
|
constructor(@InjectModel(BuildSites.name) private readonly buildSitesModel: Model<BuildSiteDocument>) { }
|
||||||
|
|
||||||
|
async findAll(projection: any, skip: number, limit: number, sort?: Record<string, 1 | -1>, filters?: Record<string, any>): Promise<ListBuildSitesResponse> {
|
||||||
|
const query: any = {}; if (filters && Object.keys(filters).length > 0) { Object.assign(query, filters) };
|
||||||
|
const totalCount = await this.buildSitesModel.countDocuments(query).exec();
|
||||||
|
const data = await this.buildSitesModel.find(query, projection, { lean: true }).skip(skip).limit(limit).sort(sort).exec();
|
||||||
|
return { data, totalCount };
|
||||||
|
}
|
||||||
|
|
||||||
|
async findById(id: Types.ObjectId, projection?: any): Promise<BuildSiteDocument | null> {
|
||||||
|
return this.buildSitesModel.findById(id, projection, { lean: false }).populate({ path: 'buildSites', select: projection?.buildSites }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(input: CreateBuildSitesInput): Promise<BuildSiteDocument> { const buildSite = new this.buildSitesModel(input); return buildSite.save() }
|
||||||
|
|
||||||
|
async update(uuid: string, input: UpdateBuildSitesInput): Promise<BuildSiteDocument> { const buildSite = await this.buildSitesModel.findOne({ uuid }); if (!buildSite) { throw new Error('BuildSite not found') }; buildSite.set(input); return buildSite.save() }
|
||||||
|
|
||||||
|
async delete(uuid: string): Promise<boolean> { const buildSite = await this.buildSitesModel.deleteMany({ uuid }); return buildSite.deletedCount > 0 }
|
||||||
|
|
||||||
|
buildProjection(fields: Record<string, any>): any {
|
||||||
|
const projection: any = {};
|
||||||
|
for (const key in fields) {
|
||||||
|
if (key === 'buildSites' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildSites.${subField}`] = 1 } }
|
||||||
|
else { projection[key] = 1 }
|
||||||
|
}; return projection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { InputType, Field } from "@nestjs/graphql";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
import { ID } from "@nestjs/graphql";
|
||||||
|
import { ExpiryBaseInput } from "@/models/base.model";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class CreateBuildSitesInput extends ExpiryBaseInput {
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
siteName: string;
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
siteNo: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
address?: Types.ObjectId;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { ObjectType, Field } from "@nestjs/graphql";
|
||||||
|
import { BuildSites } from "@/models/build-site.model";
|
||||||
|
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class ListBuildSitesResponse {
|
||||||
|
|
||||||
|
@Field(() => [BuildSites], { nullable: true })
|
||||||
|
data: BuildSites[];
|
||||||
|
|
||||||
|
@Field(() => Number, { nullable: true })
|
||||||
|
totalCount: number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { InputType, Field } from "@nestjs/graphql";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
import { ID } from "@nestjs/graphql";
|
||||||
|
import { ExpiryBaseInput } from "@/models/base.model";
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class UpdateBuildSitesInput extends ExpiryBaseInput {
|
||||||
|
|
||||||
|
@Field(() => String, { nullable: true })
|
||||||
|
siteName?: string;
|
||||||
|
|
||||||
|
@Field(() => String, { nullable: true })
|
||||||
|
siteNo?: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
address?: Types.ObjectId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ export class BuildTypesService {
|
||||||
return this.buildTypesModel.findById(id, projection, { lean: false }).populate({ path: 'buildTypes', select: projection?.buildTypes }).exec();
|
return this.buildTypesModel.findById(id, projection, { lean: false }).populate({ path: 'buildTypes', select: projection?.buildTypes }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(input: CreateBuildTypesInput): Promise<BuildTypesDocument> { const buildTypes = new this.buildTypesModel(input); console.dir({ buildTypes }); return buildTypes.save() }
|
async create(input: CreateBuildTypesInput): Promise<BuildTypesDocument> { const buildTypes = new this.buildTypesModel(input); return buildTypes.save() }
|
||||||
|
|
||||||
async update(uuid: string, input: UpdateBuildTypesInput): Promise<BuildTypesDocument> { const buildTypes = await this.buildTypesModel.findOne({ uuid }); if (!buildTypes) { throw new Error('BuildTypes not found') }; buildTypes.set(input); return buildTypes.save() }
|
async update(uuid: string, input: UpdateBuildTypesInput): Promise<BuildTypesDocument> { const buildTypes = await this.buildTypesModel.findOne({ uuid }); if (!buildTypes) { throw new Error('BuildTypes not found') }; buildTypes.set(input); return buildTypes.save() }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,6 @@ export class UpdateBuildAttributeInput {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@InputType()
|
|
||||||
export class UpdateBuildIbanInput {
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
iban?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
startDate?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
stopDate?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
bankCode?: string;
|
|
||||||
|
|
||||||
@Field({ nullable: true })
|
|
||||||
xcomment?: string;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class UpdateBuildResponsibleInput {
|
export class UpdateBuildResponsibleInput {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,55 @@
|
||||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||||
import { Document, Types } from 'mongoose';
|
|
||||||
import { ObjectType, Field, ID, Float } from '@nestjs/graphql';
|
import { ObjectType, Field, ID, Float } from '@nestjs/graphql';
|
||||||
import { Base } from '@/models/base.model';
|
import { Base } from '@/models/base.model';
|
||||||
|
import { Document, Types } from 'mongoose';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@Schema({ timestamps: true })
|
@Schema({ timestamps: true })
|
||||||
export class BuildArea extends Base {
|
export class BuildArea extends Base {
|
||||||
|
|
||||||
@Field(() => ID)
|
@Field(() => ID)
|
||||||
@Prop({ type: Types.ObjectId, ref: 'Build', required: true })
|
readonly _id: string;
|
||||||
build: Types.ObjectId;
|
|
||||||
|
|
||||||
@Field(() => Float)
|
@Field(() => Float)
|
||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
area: number;
|
areaName: string;
|
||||||
|
|
||||||
@Field(() => Float)
|
@Field(() => Float)
|
||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
|
areaCode: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
|
areaType: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
|
areaDirection: string;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
|
areaGrossSize: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
|
areaNetSize: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
|
width: number;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Prop({ required: true })
|
||||||
size: number;
|
size: number;
|
||||||
|
|
||||||
@Field()
|
@Field(() => ID, { nullable: true })
|
||||||
@Prop({ required: true })
|
@Prop({ type: Types.ObjectId, ref: 'Build', required: false })
|
||||||
type: string;
|
buildId?: Types.ObjectId;
|
||||||
|
|
||||||
@Field()
|
@Field(() => ID, { nullable: true })
|
||||||
@Prop({ required: true })
|
@Prop({ type: Types.ObjectId, ref: 'BuildType', required: false })
|
||||||
typeToken: string;
|
partTypeId?: Types.ObjectId;
|
||||||
|
|
||||||
@Field()
|
|
||||||
@Prop({ required: true })
|
|
||||||
description: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BuildAreaDocument = BuildArea & Document;
|
export type BuildAreaDocument = BuildArea & Document;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||||
|
import { Types, Document } from 'mongoose';
|
||||||
|
import { ObjectType, Field, ID } from '@nestjs/graphql';
|
||||||
|
import { Base } from '@/models/base.model';
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
@Schema({ timestamps: true })
|
||||||
|
export class BuildSites extends Base {
|
||||||
|
|
||||||
|
@Field(() => ID)
|
||||||
|
readonly _id: string;
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
@Prop({ required: true })
|
||||||
|
siteName: string;
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
@Prop({ required: true })
|
||||||
|
siteNo: string;
|
||||||
|
|
||||||
|
@Field(() => ID, { nullable: true })
|
||||||
|
@Prop({ type: Types.ObjectId, ref: 'BuildAddress', required: false })
|
||||||
|
address?: Types.ObjectId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BuildSiteDocument = BuildSites & Document;
|
||||||
|
export const BuildSiteSchema = SchemaFactory.createForClass(BuildSites);
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
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 } from '@/models/base.model';
|
import { Base, ChangableBase } 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()
|
||||||
export class BuildIban {
|
@Schema({ timestamps: true })
|
||||||
|
export class BuildIban extends ChangableBase {
|
||||||
|
|
||||||
|
@Field(() => ID)
|
||||||
|
readonly _id: string;
|
||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
iban: string;
|
iban: string;
|
||||||
|
|
@ -16,7 +21,7 @@ export class BuildIban {
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
@Prop({ required: true, default: new Date('2900-01-01T03:00:00+03:00') })
|
@Prop({ required: true })
|
||||||
stopDate: Date;
|
stopDate: Date;
|
||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
|
|
@ -26,6 +31,7 @@ export class BuildIban {
|
||||||
@Field()
|
@Field()
|
||||||
@Prop({ required: true, default: '????' })
|
@Prop({ required: true, default: '????' })
|
||||||
xcomment: string;
|
xcomment: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
|
|
@ -38,6 +44,7 @@ export class BuildResponsible {
|
||||||
@Field(() => ID)
|
@Field(() => ID)
|
||||||
@Prop({ type: Types.ObjectId, ref: Person.name, required: true })
|
@Prop({ type: Types.ObjectId, ref: Person.name, required: true })
|
||||||
person: Types.ObjectId;
|
person: Types.ObjectId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
|
|
@ -126,7 +133,7 @@ export class Build extends Base {
|
||||||
info: BuildInfo;
|
info: BuildInfo;
|
||||||
|
|
||||||
@Field(() => ID, { nullable: true })
|
@Field(() => ID, { nullable: true })
|
||||||
@Prop({ type: Types.ObjectId, ref: 'Site' })
|
@Prop({ type: Types.ObjectId, ref: 'BuildSites' })
|
||||||
site?: Types.ObjectId;
|
site?: Types.ObjectId;
|
||||||
|
|
||||||
@Field(() => ID, { nullable: true })
|
@Field(() => ID, { nullable: true })
|
||||||
|
|
@ -147,5 +154,8 @@ export class Build extends Base {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type BuildIbanDocument = BuildIban & Document;
|
||||||
|
export const BuildIbanSchema = SchemaFactory.createForClass(BuildIban);
|
||||||
|
|
||||||
export type BuildDocument = Build & Document;
|
export type BuildDocument = Build & Document;
|
||||||
export const BuildSchema = SchemaFactory.createForClass(Build);
|
export const BuildSchema = SchemaFactory.createForClass(Build);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { buildAreaAddSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = buildAreaAddSchema.parse(body);
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation CreateBuildAreaInput($input: CreateBuildAreaInput!) {
|
||||||
|
createBuildArea(input:$input) {
|
||||||
|
_id
|
||||||
|
uuid
|
||||||
|
createdAt
|
||||||
|
areaName
|
||||||
|
areaCode
|
||||||
|
areaType
|
||||||
|
areaDirection
|
||||||
|
areaGrossSize
|
||||||
|
areaNetSize
|
||||||
|
width
|
||||||
|
size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.createBuildArea, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildAreaAddSchema = 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 BuildAreaAdd = z.infer<typeof buildAreaAddSchema>;
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
|
||||||
|
const searchParams = new URL(request.url).searchParams;
|
||||||
|
const uuid = searchParams.get('uuid');
|
||||||
|
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`mutation DeleteBuildArea($uuid: String!) { deleteBuildArea(uuid: $uuid) }`;
|
||||||
|
const variables = { uuid: uuid };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.deleteBuildArea, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const { limit, skip, sort, filters } = body;
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
query BuildAreas($input: ListArguments!) {
|
||||||
|
buildAreas(input: $input) {
|
||||||
|
data {
|
||||||
|
_id
|
||||||
|
uuid
|
||||||
|
createdAt
|
||||||
|
areaName
|
||||||
|
areaCode
|
||||||
|
areaType
|
||||||
|
areaDirection
|
||||||
|
areaGrossSize
|
||||||
|
areaNetSize
|
||||||
|
width
|
||||||
|
size
|
||||||
|
expiryStarts
|
||||||
|
expiryEnds
|
||||||
|
}
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
const variables = { input: { limit, skip, sort, filters } };
|
||||||
|
console.dir({ variables })
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.buildAreas.data, totalCount: data.buildAreas.totalCount });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { UpdateBuildAddressSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const searchUrl = new URL(request.url);
|
||||||
|
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = UpdateBuildAddressSchema.parse(body);
|
||||||
|
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation UpdateBuildAddress($uuid: String!, $input: UpdateBuildAddressInput!) {
|
||||||
|
updateBuildAddress(uuid: $uuid, input: $input) {
|
||||||
|
_id
|
||||||
|
buildNumber
|
||||||
|
doorNumber
|
||||||
|
floorNumber
|
||||||
|
commentAddress
|
||||||
|
letterAddress
|
||||||
|
shortLetterAddress
|
||||||
|
latitude
|
||||||
|
longitude
|
||||||
|
street
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { uuid: uuid, input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.updateBuildAddress, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const UpdateBuildAddressSchema = z.object({
|
||||||
|
buildNumber: z.string().optional(),
|
||||||
|
doorNumber: z.string().optional(),
|
||||||
|
floorNumber: z.string().optional(),
|
||||||
|
commentAddress: z.string().optional(),
|
||||||
|
letterAddress: z.string().optional(),
|
||||||
|
shortLetterAddress: z.string().optional(),
|
||||||
|
latitude: z.number().optional(),
|
||||||
|
longitude: z.number().optional(),
|
||||||
|
street: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type UpdateBuildAddress = z.infer<typeof UpdateBuildAddressSchema>;
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { buildTypesAddSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = buildTypesAddSchema.parse(body);
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation CreateBuildAddress($input: CreateBuildAddressInput!) {
|
||||||
|
createBuildAddress(input: $input) {
|
||||||
|
_id
|
||||||
|
buildNumber
|
||||||
|
doorNumber
|
||||||
|
floorNumber
|
||||||
|
commentAddress
|
||||||
|
letterAddress
|
||||||
|
shortLetterAddress
|
||||||
|
latitude
|
||||||
|
longitude
|
||||||
|
street
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.createBuildAddress, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildTypesAddSchema = z.object({
|
||||||
|
buildNumber: z.string(),
|
||||||
|
doorNumber: z.string(),
|
||||||
|
floorNumber: z.string(),
|
||||||
|
commentAddress: z.string(),
|
||||||
|
letterAddress: z.string(),
|
||||||
|
shortLetterAddress: z.string(),
|
||||||
|
latitude: z.number(),
|
||||||
|
longitude: z.number(),
|
||||||
|
street: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildTypesAdd = z.infer<typeof buildTypesAddSchema>;
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
|
||||||
|
const searchParams = new URL(request.url).searchParams;
|
||||||
|
const uuid = searchParams.get('uuid');
|
||||||
|
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`mutation DeleteBuildAddress($uuid: String!) { deleteBuildAddress(uuid: $uuid) }`;
|
||||||
|
const variables = { uuid: uuid };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.deleteBuildAddress, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const { limit, skip, sort, filters } = body;
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
query BuildIbans($input: ListArguments!) {
|
||||||
|
buildIbans(input: $input) {
|
||||||
|
data {
|
||||||
|
iban
|
||||||
|
startDate
|
||||||
|
stopDate
|
||||||
|
bankCode
|
||||||
|
xcomment
|
||||||
|
}
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
const variables = { input: { limit, skip, sort, filters } };
|
||||||
|
console.dir({ variables })
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.buildIbans.data, totalCount: data.buildIbans.totalCount });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { UpdateBuildAddressSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const searchUrl = new URL(request.url);
|
||||||
|
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = UpdateBuildAddressSchema.parse(body);
|
||||||
|
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation UpdateBuildAddress($uuid: String!, $input: UpdateBuildAddressInput!) {
|
||||||
|
updateBuildAddress(uuid: $uuid, input: $input) {
|
||||||
|
_id
|
||||||
|
buildNumber
|
||||||
|
doorNumber
|
||||||
|
floorNumber
|
||||||
|
commentAddress
|
||||||
|
letterAddress
|
||||||
|
shortLetterAddress
|
||||||
|
latitude
|
||||||
|
longitude
|
||||||
|
street
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { uuid: uuid, input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.updateBuildAddress, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const UpdateBuildAddressSchema = z.object({
|
||||||
|
buildNumber: z.string().optional(),
|
||||||
|
doorNumber: z.string().optional(),
|
||||||
|
floorNumber: z.string().optional(),
|
||||||
|
commentAddress: z.string().optional(),
|
||||||
|
letterAddress: z.string().optional(),
|
||||||
|
shortLetterAddress: z.string().optional(),
|
||||||
|
latitude: z.number().optional(),
|
||||||
|
longitude: z.number().optional(),
|
||||||
|
street: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type UpdateBuildAddress = z.infer<typeof UpdateBuildAddressSchema>;
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { addBuildSitesSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = addBuildSitesSchema.parse(body);
|
||||||
|
console.dir({ validatedBody })
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation CreateBuildSite($input: CreateBuildSitesInput!) {
|
||||||
|
createBuildSite(input: $input) {
|
||||||
|
_id
|
||||||
|
siteName
|
||||||
|
siteNo
|
||||||
|
createdAt
|
||||||
|
expiryStarts
|
||||||
|
expiryEnds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.createBuildSite, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const addBuildSitesSchema = z.object({
|
||||||
|
siteName: z.string(),
|
||||||
|
siteNo: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type AddBuildSites = z.infer<typeof addBuildSitesSchema>;
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
|
||||||
|
const searchParams = new URL(request.url).searchParams;
|
||||||
|
const uuid = searchParams.get('uuid');
|
||||||
|
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`mutation DeleteBuildSite($uuid: String!) { deleteBuildSite(uuid: $uuid) }`;
|
||||||
|
const variables = { uuid: uuid };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.deleteBuildSite, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const body = await request.json();
|
||||||
|
const { limit, skip, sort, filters } = body;
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
query BuildSites($input: ListArguments!) {
|
||||||
|
buildSites(input: $input) {
|
||||||
|
data {
|
||||||
|
_id
|
||||||
|
uuid
|
||||||
|
siteNo
|
||||||
|
siteName
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
expiryEnds
|
||||||
|
expiryStarts
|
||||||
|
}
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
const variables = { input: { limit, skip, sort, filters } };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.buildSites.data, totalCount: data.buildSites.totalCount }, { status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
'use server';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import { GraphQLClient, gql } from 'graphql-request';
|
||||||
|
import { UpdateBuildSitesSchema } from './schema';
|
||||||
|
|
||||||
|
const endpoint = "http://localhost:3001/graphql";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const searchUrl = new URL(request.url);
|
||||||
|
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||||
|
const body = await request.json();
|
||||||
|
const validatedBody = UpdateBuildSitesSchema.parse(body);
|
||||||
|
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||||
|
try {
|
||||||
|
const client = new GraphQLClient(endpoint);
|
||||||
|
const query = gql`
|
||||||
|
mutation UpdateBuildSite($uuid: String!, $input: UpdateBuildSitesInput!) {
|
||||||
|
updateBuildSite(uuid: $uuid, input: $input) {
|
||||||
|
uuid
|
||||||
|
siteNo
|
||||||
|
siteName
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
const variables = { uuid: uuid, input: validatedBody };
|
||||||
|
const data = await client.request(query, variables);
|
||||||
|
return NextResponse.json({ data: data.updateBuildSite, status: 200 });
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const UpdateBuildSitesSchema = z.object({
|
||||||
|
siteName: z.string().optional(),
|
||||||
|
siteNo: z.string().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export type UpdateBuildSites = z.infer<typeof UpdateBuildSitesSchema>;
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
const BuildAreasAdd = () => { return <><div>BuildAreasAdd</div></> }
|
||||||
|
|
||||||
|
export default BuildAreasAdd;
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
const BuildAreas = () => {
|
||||||
|
return <><div>BuildAreas</div></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BuildAreas;
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
const BuildAreasUpdate = () => {
|
||||||
|
return <><div>BuildAreasUpdate</div></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BuildAreasUpdate;
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
const BuildIbansAdd = () => { return <><div>BuildIbansAdd</div></> }
|
||||||
|
|
||||||
|
export default BuildIbansAdd;
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
const BuildIbans = () => {
|
||||||
|
return <><div>BuildIbans</div></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BuildIbans;
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
const BuildIbansUpdate = () => {
|
||||||
|
return <><div>BuildIbansUpdate</div></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BuildIbansUpdate;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageAddBuildSites } from "@/pages/build-sites/add/page";
|
||||||
|
|
||||||
|
const BuildSitesAdd = () => { return <><PageAddBuildSites /></> }
|
||||||
|
|
||||||
|
export default BuildSitesAdd;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageBuildSites } from "@/pages/build-sites/page";
|
||||||
|
|
||||||
|
const BuildSites = () => { return <><PageBuildSites /></> }
|
||||||
|
|
||||||
|
export default BuildSites;
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { PageUpdateBuildSites } from "@/pages/build-sites/update/page";
|
||||||
|
|
||||||
|
const BuildSitesUpdate = () => { return <><PageUpdateBuildSites /></> }
|
||||||
|
|
||||||
|
export default BuildSitesUpdate;
|
||||||
|
|
@ -2,23 +2,16 @@
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import {
|
import {
|
||||||
IconCamera,
|
|
||||||
IconChartBar,
|
|
||||||
IconDashboard,
|
|
||||||
IconDatabase,
|
|
||||||
IconFileAi,
|
|
||||||
IconFileDescription,
|
|
||||||
IconFileWord,
|
|
||||||
IconFolder,
|
|
||||||
IconHelp,
|
|
||||||
IconInnerShadowTop,
|
IconInnerShadowTop,
|
||||||
IconListDetails,
|
IconListDetails,
|
||||||
IconReport,
|
|
||||||
IconAddressBook,
|
IconAddressBook,
|
||||||
IconSettings,
|
|
||||||
IconUsers,
|
IconUsers,
|
||||||
IconBuilding,
|
IconBuilding,
|
||||||
IconTypeface
|
IconTypeface,
|
||||||
|
IconMessageCircle,
|
||||||
|
IconChartArea,
|
||||||
|
IconCreditCard,
|
||||||
|
|
||||||
} from "@tabler/icons-react"
|
} from "@tabler/icons-react"
|
||||||
|
|
||||||
import { NavMain } from "@/components/dashboard/nav-main"
|
import { NavMain } from "@/components/dashboard/nav-main"
|
||||||
|
|
@ -46,27 +39,42 @@ const data = {
|
||||||
{
|
{
|
||||||
title: "Users",
|
title: "Users",
|
||||||
url: "/users",
|
url: "/users",
|
||||||
icon: IconUsers,
|
icon: IconUsers
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "People",
|
title: "People",
|
||||||
url: "/people",
|
url: "/people",
|
||||||
icon: IconListDetails,
|
icon: IconListDetails
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Build",
|
title: "Build",
|
||||||
url: "/build",
|
url: "/build",
|
||||||
icon: IconBuilding,
|
icon: IconBuilding
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Build Types",
|
title: "Build Types",
|
||||||
url: "/build-types",
|
url: "/build-types",
|
||||||
icon: IconTypeface,
|
icon: IconTypeface
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Build Addresses",
|
title: "Build Addresses",
|
||||||
url: "/build-address",
|
url: "/build-address",
|
||||||
icon: IconAddressBook,
|
icon: IconAddressBook
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Build Sites",
|
||||||
|
url: "/build-sites",
|
||||||
|
icon: IconMessageCircle
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Build Areas",
|
||||||
|
url: "/build-areas",
|
||||||
|
icon: IconChartArea
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Build ibans",
|
||||||
|
url: "/build-ibans",
|
||||||
|
icon: IconCreditCard
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
navClouds: [
|
navClouds: [
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function PeopleDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildAddressMutation()
|
const deleteMutation = useDeleteBuildAddressMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ export function BuildAddressDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildAddressMutation()
|
const deleteMutation = useDeleteBuildAddressMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,10 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const buildAddressUpdateSchema = z.object({
|
export const buildAddressUpdateSchema = z.object({
|
||||||
buildNumber: z.string().optional(),
|
siteNo: z.string().optional(),
|
||||||
doorNumber: z.string().optional(),
|
siteName: z.string().optional(),
|
||||||
floorNumber: z.string().optional(),
|
|
||||||
commentAddress: z.string().optional(),
|
|
||||||
letterAddress: z.string().optional(),
|
|
||||||
shortLetterAddress: z.string().optional(),
|
|
||||||
latitude: z.number().optional(),
|
|
||||||
longitude: z.number().optional(),
|
|
||||||
street: z.string().optional(),
|
|
||||||
expiryStarts: z.string().optional(),
|
|
||||||
expiryEnds: z.string().optional(),
|
expiryEnds: z.string().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type BuildAddressUpdate = z.infer<typeof buildAddressUpdateSchema>;
|
export type BuildAddressUpdate = z.infer<typeof buildAddressUpdateSchema>;
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function BuildAddressDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeletePersonMutation()
|
const deleteMutation = useDeletePersonMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
"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 { BuildSitesAdd, buildSitesAddSchema } from "./schema"
|
||||||
|
import { useAddBuildSitesMutation } from "./queries"
|
||||||
|
|
||||||
|
const BuildSitesForm = ({ refetchTable }: { refetchTable: () => void }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildSitesAdd>({
|
||||||
|
resolver: zodResolver(buildSitesAddSchema),
|
||||||
|
defaultValues: {
|
||||||
|
siteNo: "",
|
||||||
|
siteName: "",
|
||||||
|
expiryStarts: "",
|
||||||
|
expiryEnds: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
|
const mutation = useAddBuildSitesMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildSitesAdd) { 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="siteNo"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site No</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="12A" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="siteName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Door Number</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="3" {...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 { BuildSitesForm }
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { BuildSitesForm } from '@/pages/build-sites/add/form';
|
||||||
|
import { BuildSitesDataTableAdd } from './table/data-table';
|
||||||
|
import { useGraphQlBuildSitesList } from '@/pages/build-sites/queries';
|
||||||
|
|
||||||
|
const PageAddBuildSites = () => {
|
||||||
|
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 } = useGraphQlBuildSitesList({ limit, skip: (page - 1) * limit, sort, filters });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildSitesDataTableAdd
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildSitesForm refetchTable={refetch} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageAddBuildSites };
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
import { BuildSitesAdd } from './schema';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildSitesAdd = async (record: BuildSitesAdd): Promise<{ data: BuildSitesAdd | 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-sites/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 useAddBuildSitesMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data }: { data: BuildSitesAdd }) => fetchGraphQlBuildSitesAdd(data),
|
||||||
|
onSuccess: () => { console.log("Build sites created successfully") },
|
||||||
|
onError: (error) => { console.error("Add build sites failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildSitesAddSchema = z.object({
|
||||||
|
siteNo: z.string(),
|
||||||
|
siteName: z.string(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildSitesAdd = z.infer<typeof buildSitesAddSchema>;
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
"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: "siteName",
|
||||||
|
header: "Site Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "siteNo",
|
||||||
|
header: "Site No",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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 BuildSitesDataTableAdd({
|
||||||
|
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-sites") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build Sites</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,14 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
siteNo: z.string().optional(),
|
||||||
|
siteName: z.string().optional(),
|
||||||
|
createdAt: z.string().optional(),
|
||||||
|
updatedAt: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
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,80 @@
|
||||||
|
"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: "siteName",
|
||||||
|
header: "Site Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "siteNo",
|
||||||
|
header: "Site No",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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,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 { useDeleteBuildSiteMutation } from "../queries"
|
||||||
|
|
||||||
|
export function BuildSitesDataTable({
|
||||||
|
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 = 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,
|
||||||
|
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-sites/add") }}>
|
||||||
|
<IconPlus />
|
||||||
|
<span className="hidden lg:inline">Add Build Sites</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,14 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
siteName: z.string(),
|
||||||
|
siteNo: 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 { BuildSitesDataTable } from './list/data-table';
|
||||||
|
import { useGraphQlBuildSitesList } from './queries';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
const PageBuildSites = () => {
|
||||||
|
|
||||||
|
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 } = useGraphQlBuildSitesList({ 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 sites</div> }
|
||||||
|
|
||||||
|
return <BuildSitesDataTable data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit} onPageChange={handlePageChange} onPageSizeChange={handlePageSizeChange} refetchTable={refetch} />;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { PageBuildSites };
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client'
|
||||||
|
import { useQuery, useMutation } from '@tanstack/react-query'
|
||||||
|
import { ListArguments } from '@/types/listRequest'
|
||||||
|
|
||||||
|
const fetchGraphQlBuildSitesList = 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-sites/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 fetchGraphQlDeleteBuildSite = async (uuid: string): Promise<boolean> => {
|
||||||
|
console.log('Fetching test data from local API');
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/build-sites/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 useGraphQlBuildSitesList(params: ListArguments) {
|
||||||
|
return useQuery({ queryKey: ['graphql-build-sites-list', params], queryFn: () => fetchGraphQlBuildSitesList(params) })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDeleteBuildSiteMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ uuid }: { uuid: string }) => fetchGraphQlDeleteBuildSite(uuid),
|
||||||
|
onSuccess: () => { console.log("Build site deleted successfully") },
|
||||||
|
onError: (error) => { console.error("Delete build site 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,104 @@
|
||||||
|
"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 { BuildAddressUpdate, buildAddressUpdateSchema } from "@/pages/build-sites/update/schema"
|
||||||
|
|
||||||
|
const BuildAddressForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: () => void, initData: BuildAddressUpdate, selectedUuid: string }) => {
|
||||||
|
|
||||||
|
const form = useForm<BuildAddressUpdate>({ resolver: zodResolver(buildAddressUpdateSchema), defaultValues: { ...initData } })
|
||||||
|
|
||||||
|
const { handleSubmit } = form
|
||||||
|
|
||||||
|
const mutation = useUpdateBuildSitesMutation();
|
||||||
|
|
||||||
|
function onSubmit(values: BuildAddressUpdate) { 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="siteNo"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site Number</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="12A" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="siteName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Site Name</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="3" {...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 Address
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BuildAddressForm }
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use client';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useGraphQlBuildSitesList } from '@/pages/build-sites/queries';
|
||||||
|
import { BuildAddressDataTableUpdate } from '@/pages/build-sites/update/table/data-table';
|
||||||
|
import { BuildAddressForm } from '@/pages/build-sites/update/form';
|
||||||
|
import { useSearchParams, useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
|
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-sites')}>Back to Build Sites</Button>
|
||||||
|
</>
|
||||||
|
if (!uuid) { return backToBuildAddress }
|
||||||
|
const { data, isLoading, error, refetch } = useGraphQlBuildSitesList({ limit, skip: (page - 1) * limit, sort, filters: { ...filters, uuid } });
|
||||||
|
const initData = data?.data?.[0] || null;
|
||||||
|
if (!initData) { return backToBuildAddress }
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<BuildAddressDataTableUpdate
|
||||||
|
data={data?.data || []} totalCount={data?.totalCount || 0} currentPage={page} pageSize={limit}
|
||||||
|
onPageChange={setPage} onPageSizeChange={setLimit} refetchTable={refetch}
|
||||||
|
/>
|
||||||
|
<BuildAddressForm refetchTable={refetch} initData={initData} selectedUuid={uuid} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PageUpdateBuildSites };
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
'use client'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { UpdateBuildSitesUpdate } from './types';
|
||||||
|
import { toISOIfNotZ } from '@/lib/utils';
|
||||||
|
|
||||||
|
const fetchGraphQlBuildAddressUpdate = async (record: UpdateBuildSitesUpdate, uuid: string): Promise<{ data: UpdateBuildSitesUpdate | 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-sites/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 useUpdateBuildSitesMutation() {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ data, uuid }: { data: UpdateBuildSitesUpdate, uuid: string }) => fetchGraphQlBuildAddressUpdate(data, uuid),
|
||||||
|
onSuccess: () => { console.log("Build Sites updated successfully") },
|
||||||
|
onError: (error) => { console.error("Update Build Sites failed:", error) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const buildAddressUpdateSchema = z.object({
|
||||||
|
|
||||||
|
siteNo: z.string().optional(),
|
||||||
|
siteName: z.string().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional()
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BuildAddressUpdate = z.infer<typeof buildAddressUpdateSchema>;
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
"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: "siteName",
|
||||||
|
header: "Site Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "siteNo",
|
||||||
|
header: "Site No",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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 BuildAddressDataTableUpdate({
|
||||||
|
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-sites") }}>
|
||||||
|
<Home />
|
||||||
|
<span className="hidden lg:inline">Back to Build Sites</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,14 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const schema = z.object({
|
||||||
|
_id: z.string(),
|
||||||
|
uuid: z.string(),
|
||||||
|
siteNo: z.string().optional(),
|
||||||
|
siteName: z.string().optional(),
|
||||||
|
createdAt: z.string().optional(),
|
||||||
|
updatedAt: z.string().optional(),
|
||||||
|
expiryEnds: z.string().optional(),
|
||||||
|
expiryStarts: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type schemaType = z.infer<typeof schema>;
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
interface UpdateBuildSitesUpdate {
|
||||||
|
siteNo: string;
|
||||||
|
siteName: string;
|
||||||
|
expiryStarts?: string;
|
||||||
|
expiryEnds?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { UpdateBuildSitesUpdate };
|
||||||
|
|
@ -100,7 +100,7 @@ export function BuildTypesDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ export function BuildTypesDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteBuildTypeMutation()
|
const deleteMutation = useDeleteBuildTypeMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function BuildTypesDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeletePersonMutation()
|
const deleteMutation = useDeletePersonMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function BuildDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function PeopleDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function PeopleDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,8 @@ const PeopleForm = ({ refetchTable, initData, selectedUuid }: { refetchTable: ()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6 p-4" >
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
className="space-y-6 p-4"
|
|
||||||
>
|
|
||||||
{/* BASIC INFO */}
|
{/* BASIC INFO */}
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function PeopleDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeletePersonMutation()
|
const deleteMutation = useDeletePersonMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function UserDataTableAdd({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function UserDataTable({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export function UserDataTableUpdate({
|
||||||
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
const dataIds = React.useMemo<UniqueIdentifier[]>(() => data?.map(({ _id }) => _id) || [], [data])
|
||||||
|
|
||||||
const deleteMutation = useDeleteUserMutation()
|
const deleteMutation = useDeleteUserMutation()
|
||||||
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 200) }
|
const deleteHandler = (id: string) => { deleteMutation.mutate({ uuid: id }); setTimeout(() => { refetchTable() }, 400) }
|
||||||
const columns = getColumns(router, deleteHandler);
|
const columns = getColumns(router, deleteHandler);
|
||||||
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
const pagination = React.useMemo(() => ({ pageIndex: currentPage - 1, pageSize: pageSize, }), [currentPage, pageSize])
|
||||||
const totalPages = Math.ceil(totalCount / pageSize)
|
const totalPages = Math.ceil(totalCount / pageSize)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { BuildIbanService } from './build-iban.service';
|
|
||||||
import { BuildIbanResolver } from './build-iban.resolver';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
providers: [BuildIbanService, BuildIbanResolver]
|
|
||||||
})
|
|
||||||
export class BuildIbanModule {}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
import { Resolver } from '@nestjs/graphql';
|
|
||||||
|
|
||||||
@Resolver()
|
|
||||||
export class BuildIbanResolver {}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BuildIbanService {}
|
|
||||||
Loading…
Reference in New Issue