-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!--- Please provide a general summary of your changes in the title above --> # Pull Request type <!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): Issue Number: - IN-965 - IN-966 ## Does this introduce a breaking change? - [ ] Yes - [ ] No <!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. --> ## Summary by CodeRabbit - **New Features** - Introduced attribute editing capabilities in the API and UI, allowing for modifications such as toggling active status and deleting attributes. - Enhanced service editing interfaces with new components and logic for attribute management. - Added default values in forms for better initial user interaction and data handling. - **Refactor** - Restructured service processing logic for better clarity and maintainability, including handling of various service-related attributes. - Improved error handling and data structure updates in service modals. - **Documentation** - Added and updated type definitions and interfaces for service processing, enhancing development clarity and supporting new features. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3a2f374
commit da82c52
Showing
34 changed files
with
1,694 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/api/router/component/mutation.AttributeEditWrapper.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getAuditedClient } from '@weareinreach/db' | ||
import { handleError } from '~api/lib/errorHandler' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TAttributeEditWrapperSchema } from './mutation.AttributeEditWrapper.schema' | ||
|
||
export const AttributeEditWrapper = async ({ | ||
ctx, | ||
input, | ||
}: TRPCHandlerParams<TAttributeEditWrapperSchema, 'protected'>) => { | ||
try { | ||
const prisma = getAuditedClient(ctx.actorId) | ||
|
||
const { id, action } = input | ||
if (action === 'delete') { | ||
const deleteResult = await prisma.attributeSupplement.delete({ | ||
where: { id }, | ||
}) | ||
return deleteResult | ||
} | ||
|
||
const current = await prisma.attributeSupplement.findUniqueOrThrow({ | ||
where: { id }, | ||
select: { active: true }, | ||
}) | ||
const updateResult = await prisma.attributeSupplement.update({ | ||
where: { id }, | ||
data: { active: !current.active }, | ||
}) | ||
return updateResult | ||
} catch (error) { | ||
return handleError(error) | ||
} | ||
} | ||
export default AttributeEditWrapper |
9 changes: 9 additions & 0 deletions
9
packages/api/router/component/mutation.AttributeEditWrapper.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { z } from 'zod' | ||
|
||
import { prefixedId } from '~api/schemas/idPrefix' | ||
|
||
export const ZAttributeEditWrapperSchema = z.object({ | ||
id: prefixedId('attributeSupplement'), | ||
action: z.enum(['toggleActive', 'delete']), | ||
}) | ||
export type TAttributeEditWrapperSchema = z.infer<typeof ZAttributeEditWrapperSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
generateId, | ||
generateNestedFreeText, | ||
generateNestedFreeTextUpsert, | ||
getAuditedClient, | ||
Prisma, | ||
} from '@weareinreach/db' | ||
import { handleError } from '~api/lib/errorHandler' | ||
import { connectOne, createOne } from '~api/schemas/nestedOps' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type Create, type TUpsertSchema } from './mutation.upsert.schema' | ||
|
||
type CreateData = Pick<Create, 'url' | 'isPrimary' | 'deleted' | 'published' | 'orgLocationOnly'> | ||
export const upsert = async ({ ctx, input }: TRPCHandlerParams<TUpsertSchema, 'protected'>) => { | ||
try { | ||
const prisma = getAuditedClient(ctx.actorId) | ||
const { description: desc, operation, id: passedId, orgLocationId, organizationId, ...data } = input | ||
|
||
const isCreateData = (op: 'create' | 'update', inputData: typeof data): inputData is CreateData => | ||
op === 'create' | ||
const isCreate = operation === 'create' | ||
|
||
const id = isCreate ? passedId ?? generateId('orgEmail') : passedId | ||
|
||
const generateDescription = (): | ||
| Prisma.FreeTextCreateNestedOneWithoutOrgWebsiteInput | ||
| Prisma.FreeTextUpdateOneWithoutOrgWebsiteNestedInput | ||
| undefined => { | ||
if (!desc || !organizationId) { | ||
return undefined | ||
} | ||
if (isCreateData(operation, data)) { | ||
return Prisma.validator<Prisma.FreeTextCreateNestedOneWithoutOrgWebsiteInput>()( | ||
generateNestedFreeText({ | ||
orgId: organizationId, | ||
text: desc, | ||
type: 'websiteDesc', | ||
itemId: id, | ||
}) | ||
) | ||
} else { | ||
return Prisma.validator<Prisma.FreeTextUpdateOneWithoutOrgWebsiteNestedInput>()( | ||
generateNestedFreeTextUpsert({ | ||
orgId: organizationId, | ||
text: desc, | ||
type: 'websiteDesc', | ||
itemId: id, | ||
}) | ||
) | ||
} | ||
} | ||
const description = generateDescription() | ||
|
||
const result = isCreateData(operation, data) | ||
? await prisma.orgWebsite.create({ | ||
data: { | ||
id, | ||
...(description && { description }), | ||
...data, | ||
locations: createOne(orgLocationId, 'orgLocationId'), | ||
organization: connectOne(organizationId, 'id'), | ||
}, | ||
}) | ||
: await prisma.orgWebsite.update({ | ||
where: { id }, | ||
data: { | ||
...(description && { description }), | ||
...data, | ||
}, | ||
}) | ||
|
||
return result | ||
} catch (error) { | ||
return handleError(error) | ||
} | ||
} | ||
export default upsert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { z } from 'zod' | ||
|
||
import { prefixedId } from '~api/schemas/idPrefix' | ||
|
||
const base = z | ||
.object({ | ||
id: prefixedId('orgWebsite'), | ||
url: z.string().url('Invalid URL. Must start with either "https://" or "http://"'), | ||
description: z.string().nullable(), | ||
isPrimary: z.boolean(), | ||
published: z.boolean(), | ||
deleted: z.boolean(), | ||
organizationId: prefixedId('organization'), | ||
orgLocationId: prefixedId('orgLocation').nullable(), | ||
orgLocationOnly: z.boolean(), | ||
}) | ||
.partial() | ||
|
||
const create = z | ||
.object({ | ||
operation: z.literal('create'), | ||
}) | ||
.merge(base.required({ url: true, organizationId: true })) | ||
const update = z | ||
.object({ | ||
operation: z.literal('update'), | ||
}) | ||
.merge(base.required({ id: true })) | ||
|
||
export type Create = z.infer<typeof create> | ||
export type Update = z.infer<typeof update> | ||
|
||
export const ZUpsertSchema = z.discriminatedUnion('operation', [create, update]) | ||
export type TUpsertSchema = z.infer<typeof ZUpsertSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.