Skip to content

Commit 9e02247

Browse files
committed
address more comments
1 parent 01a7fbc commit 9e02247

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

apps/sim/app/api/tools/workday/create-prehire/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const RequestSchema = z.object({
1818
email: z.string().optional(),
1919
phoneNumber: z.string().optional(),
2020
address: z.string().optional(),
21+
countryCode: z.string().optional(),
2122
})
2223

2324
export async function POST(request: NextRequest) {
@@ -46,6 +47,13 @@ export async function POST(request: NextRequest) {
4647
const firstName = parts[0] ?? ''
4748
const lastName = parts.length > 1 ? parts.slice(1).join(' ') : ''
4849

50+
if (!lastName) {
51+
return NextResponse.json(
52+
{ success: false, error: 'Legal name must include both a first name and last name' },
53+
{ status: 400 }
54+
)
55+
}
56+
4957
const client = await createWorkdaySoapClient(
5058
data.tenantUrl,
5159
data.tenant,
@@ -96,7 +104,7 @@ export async function POST(request: NextRequest) {
96104
Name_Data: {
97105
Legal_Name_Data: {
98106
Name_Detail_Data: {
99-
Country_Reference: wdRef('ISO_3166-1_Alpha-2_Code', 'US'),
107+
Country_Reference: wdRef('ISO_3166-1_Alpha-2_Code', data.countryCode ?? 'US'),
100108
First_Name: firstName,
101109
Last_Name: lastName,
102110
},

apps/sim/app/api/tools/workday/get-compensation/route.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
44
import { checkInternalAuth } from '@/lib/auth/hybrid'
55
import { generateRequestId } from '@/lib/core/utils/request'
6-
import { createWorkdaySoapClient } from '@/tools/workday/soap'
6+
import { createWorkdaySoapClient, extractRefId, type WorkdayReference } from '@/tools/workday/soap'
77

88
export const dynamic = 'force-dynamic'
99

@@ -57,15 +57,35 @@ export async function POST(request: NextRequest) {
5757
const workerInner = workerData?.Worker_Data as Record<string, unknown> | undefined
5858
const compensationData = workerInner?.Compensation_Data as Record<string, unknown> | undefined
5959

60-
const rawPlans = compensationData?.Compensation_Plan_Assignment
61-
const plansArray = (Array.isArray(rawPlans) ? rawPlans : rawPlans ? [rawPlans] : []) as Record<
62-
string,
63-
unknown
64-
>[]
60+
const mapPlan = (p: Record<string, unknown>) => ({
61+
id: extractRefId(p.Compensation_Plan_Reference as WorkdayReference | undefined) ?? null,
62+
planName:
63+
(p.Compensation_Plan_Reference as Record<string, unknown> | undefined)?.attributes
64+
?.Descriptor ?? null,
65+
amount: p.Amount ?? p.Per_Unit_Amount ?? p.Individual_Target_Amount ?? null,
66+
currency: extractRefId(p.Currency_Reference as WorkdayReference | undefined) ?? null,
67+
frequency: extractRefId(p.Frequency_Reference as WorkdayReference | undefined) ?? null,
68+
})
6569

66-
const compensationPlans = plansArray.map((p) => ({
67-
...p,
68-
}))
70+
const planTypes = [
71+
'Employee_Base_Pay_Plan_Assignment_Data',
72+
'Employee_Salary_Unit_Plan_Assignment_Data',
73+
'Employee_Bonus_Plan_Assignment_Data',
74+
'Employee_Allowance_Plan_Assignment_Data',
75+
'Employee_Commission_Plan_Assignment_Data',
76+
'Employee_Stock_Plan_Assignment_Data',
77+
'Employee_Period_Salary_Plan_Assignment_Data',
78+
] as const
79+
80+
const compensationPlans: ReturnType<typeof mapPlan>[] = []
81+
for (const planType of planTypes) {
82+
const raw = compensationData?.[planType]
83+
if (!raw) continue
84+
const arr = Array.isArray(raw) ? raw : [raw]
85+
for (const p of arr) {
86+
compensationPlans.push(mapPlan(p as Record<string, unknown>))
87+
}
88+
}
6989

7090
return NextResponse.json({
7191
success: true,

apps/sim/blocks/blocks/workday.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ export const WorkdayBlock: BlockConfig = {
144144
condition: { field: 'operation', value: 'create_prehire' },
145145
mode: 'advanced',
146146
},
147+
{
148+
id: 'countryCode',
149+
title: 'Country Code',
150+
type: 'short-input',
151+
placeholder: 'US',
152+
condition: { field: 'operation', value: 'create_prehire' },
153+
mode: 'advanced',
154+
description: 'ISO 3166-1 Alpha-2 country code (defaults to US)',
155+
},
147156

148157
// Hire Employee
149158
{
@@ -368,8 +377,12 @@ Output: {"businessTitle": "Senior Engineer"}`,
368377
}
369378

370379
if (fields && operation === 'update_worker') {
371-
const parsedFields = typeof fields === 'string' ? JSON.parse(fields) : fields
372-
return { ...rest, fields: parsedFields }
380+
try {
381+
const parsedFields = typeof fields === 'string' ? JSON.parse(fields) : fields
382+
return { ...rest, fields: parsedFields }
383+
} catch {
384+
throw new Error('Invalid JSON in Fields block')
385+
}
373386
}
374387

375388
return rest
@@ -389,6 +402,7 @@ Output: {"businessTitle": "Senior Engineer"}`,
389402
email: { type: 'string', description: 'Email address' },
390403
phoneNumber: { type: 'string', description: 'Phone number' },
391404
address: { type: 'string', description: 'Address' },
405+
countryCode: { type: 'string', description: 'ISO 3166-1 Alpha-2 country code' },
392406
preHireId: { type: 'string', description: 'Pre-hire record ID' },
393407
positionId: { type: 'string', description: 'Position ID' },
394408
hireDate: { type: 'string', description: 'Hire date (YYYY-MM-DD)' },

apps/sim/components/icons.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ export function NoteIcon(props: SVGProps<SVGSVGElement>) {
125125
}
126126

127127
export function WorkdayIcon(props: SVGProps<SVGSVGElement>) {
128+
const id = useId()
129+
const clipId = `workday_clip_${id}`
128130
return (
129131
<svg {...props} viewBox='0 0 64 64' fill='none' xmlns='http://www.w3.org/2000/svg'>
130-
<g clipPath='url(#workday-clip)' transform='matrix(0.53333333,0,0,0.53333333,-124.63685,-16)'>
132+
<g clipPath={`url(#${clipId})`} transform='matrix(0.53333333,0,0,0.53333333,-124.63685,-16)'>
131133
<path
132134
fillRule='evenodd'
133135
clipRule='evenodd'
@@ -142,7 +144,7 @@ export function WorkdayIcon(props: SVGProps<SVGSVGElement>) {
142144
/>
143145
</g>
144146
<defs>
145-
<clipPath id='workday-clip'>
147+
<clipPath id={clipId}>
146148
<path d='M 354,30 H 234 v 120 h 120 z' fill='#ffffff' />
147149
</clipPath>
148150
</defs>

apps/sim/tools/workday/create_prehire.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export const createPrehireTool: ToolConfig<
6363
visibility: 'user-or-llm',
6464
description: 'Address of the pre-hire',
6565
},
66+
countryCode: {
67+
type: 'string',
68+
required: false,
69+
visibility: 'user-or-llm',
70+
description: 'ISO 3166-1 Alpha-2 country code (defaults to US)',
71+
},
6672
},
6773

6874
request: {

apps/sim/tools/workday/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface WorkdayCreatePrehireParams extends WorkdayBaseParams {
5959
email?: string
6060
phoneNumber?: string
6161
address?: string
62+
countryCode?: string
6263
}
6364

6465
export interface WorkdayCreatePrehireResponse extends ToolResponse {

0 commit comments

Comments
 (0)