export function policyAcknowledgment(form: FormTs) {
// Policy Acknowledgment Form - Compliance Confirmation
// Demonstrates: TextPanel for policy display, required checkboxes, dynamic labels, Slider, Datepicker
// ============================================
// STATE
// ============================================
const allAcknowledged = form.state(false);
const acknowledgmentCount = form.state(0);
const totalRequired = 5;
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Policy Acknowledgment',
computedValue: () => 'Please review and acknowledge the following policy',
customStyles: {
backgroundColor: '#7c3aed',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Policy Selection
// ============================================
const policySelection = form.addSubform('policySelection', {
title: 'Policy Information'
});
policySelection.addRow(row => {
row.addDropdown('policyType', {
label: 'Policy Document',
options: [
{ id: 'code-of-conduct', name: 'Code of Conduct' },
{ id: 'data-privacy', name: 'Data Privacy Policy' },
{ id: 'it-security', name: 'IT Security Policy' },
{ id: 'anti-harassment', name: 'Anti-Harassment Policy' },
{ id: 'remote-work', name: 'Remote Work Policy' },
{ id: 'social-media', name: 'Social Media Policy' }
],
isRequired: true,
placeholder: 'Select a policy to review'
}, '1fr');
row.addTextbox('policyVersion', {
label: 'Policy Version',
defaultValue: 'v2.1',
isReadOnly: true
}, '150px');
});
policySelection.addRow(row => {
row.addDatepicker('effectiveDate', {
label: 'Policy Effective Date',
defaultValue: '2024-01-01',
isReadOnly: true
}, '1fr');
row.addDatepicker('reviewDeadline', {
label: 'Acknowledgment Deadline',
defaultValue: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10),
isReadOnly: true
}, '1fr');
});
// ============================================
// SECTION 2: Policy Content Display
// ============================================
const policyContent = form.addSubform('policyContent', {
title: () => {
const policy = policySelection.dropdown('policyType')?.value();
if (!policy) return 'Policy Content';
const names: Record<string, string> = {
'code-of-conduct': 'Code of Conduct',
'data-privacy': 'Data Privacy Policy',
'it-security': 'IT Security Policy',
'anti-harassment': 'Anti-Harassment Policy',
'remote-work': 'Remote Work Policy',
'social-media': 'Social Media Policy'
};
return names[policy] || 'Policy Content';
},
isVisible: () => !!policySelection.dropdown('policyType')?.value(),
customStyles: { backgroundColor: '#f5f3ff', padding: '16px', borderRadius: '8px' }
});
policyContent.addRow(row => {
row.addTextPanel('policyText', {
computedValue: () => {
const policy = policySelection.dropdown('policyType')?.value();
if (policy === 'code-of-conduct') {
return `CODE OF CONDUCT POLICY
1. PROFESSIONAL BEHAVIOR
All employees are expected to conduct themselves in a professional manner that reflects positively on the organization. This includes treating colleagues, clients, and partners with respect and dignity.
2. INTEGRITY AND HONESTY
Employees must act with integrity in all business dealings. This includes accurate reporting, honest communication, and ethical decision-making.
3. CONFIDENTIALITY
Proprietary information, trade secrets, and confidential business data must be protected. Employees may not disclose confidential information to unauthorized parties.
4. CONFLICT OF INTEREST
Employees must avoid situations where personal interests conflict with company interests. Any potential conflicts must be disclosed to management.
5. COMPLIANCE
All employees must comply with applicable laws, regulations, and company policies. Violations may result in disciplinary action up to and including termination.`;
}
if (policy === 'data-privacy') {
return `DATA PRIVACY POLICY
1. DATA COLLECTION
We collect only data necessary for business purposes. All data collection must have a lawful basis and be documented.
2. DATA PROTECTION
Personal data must be protected using appropriate technical and organizational measures. This includes encryption, access controls, and secure storage.
3. DATA RETENTION
Data should only be retained for as long as necessary. Retention periods are defined by data type and legal requirements.
4. DATA SUBJECT RIGHTS
Individuals have rights regarding their personal data including access, correction, deletion, and portability. All requests must be handled within legal timeframes.
5. BREACH NOTIFICATION
Any suspected data breach must be reported immediately to the Data Protection Officer. Affected individuals and authorities will be notified as required by law.`;
}
if (policy === 'it-security') {
return `IT SECURITY POLICY
1. PASSWORD REQUIREMENTS
Passwords must be at least 12 characters with complexity requirements. Passwords must be changed every 90 days and never shared.
2. DEVICE SECURITY
All company devices must have approved security software. Personal devices accessing company data must meet security standards.
3. NETWORK ACCESS
Secure VPN must be used for remote access. Public WiFi should be avoided for sensitive work.
4. EMAIL AND PHISHING
Be vigilant about phishing attempts. Never click suspicious links or download unexpected attachments. Report suspected phishing immediately.
5. INCIDENT REPORTING
Any security incident or suspected compromise must be reported to IT Security within 24 hours. Failure to report may result in disciplinary action.`;
}
return `Please select a policy from the dropdown above to view its content.
The full policy text will appear here once you select a policy document.`;
},
customStyles: {
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
border: '1px solid #e5e7eb',
whiteSpace: 'pre-wrap',
fontFamily: 'system-ui',
fontSize: '14px',
lineHeight: '1.6'
}
});
});
// ============================================
// SECTION 3: Understanding Check
// ============================================
const understandingSection = form.addSubform('understanding', {
title: 'Policy Understanding',
isVisible: () => !!policySelection.dropdown('policyType')?.value()
});
understandingSection.addRow(row => {
row.addSlider('comprehension', {
label: 'How well do you understand this policy?',
min: 1,
max: 10,
step: 1,
defaultValue: 5,
showValue: true,
unit: '/10'
});
});
understandingSection.addRow(row => {
row.addThumbRating('needsClarification', {
label: 'Do you need any clarification on this policy?',
upLabel: 'Yes, I have questions',
downLabel: 'No, I understand fully',
showLabels: true,
alignment: 'center',
size: 'lg'
});
});
understandingSection.addSpacer();
understandingSection.addRow(row => {
row.addTextarea('questions', {
label: 'Questions or areas needing clarification:',
placeholder: 'Enter any questions you have about this policy...',
rows: 3,
isVisible: () => understandingSection.thumbRating('needsClarification')?.value() === 'up'
});
});
// ============================================
// SECTION 4: Acknowledgment Checkboxes
// ============================================
const acknowledgmentSection = form.addSubform('acknowledgments', {
title: () => `Required Acknowledgments (${acknowledgmentCount()}/${totalRequired})`,
isVisible: () => !!policySelection.dropdown('policyType')?.value(),
customStyles: () => {
if (allAcknowledged()) {
return { backgroundColor: '#d1fae5', padding: '16px', borderRadius: '8px' };
}
return { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' };
}
});
acknowledgmentSection.addRow(row => {
row.addTextPanel('ackInstructions', {
computedValue: () => allAcknowledged()
? 'All required acknowledgments completed.'
: 'Please check each box to confirm your understanding and agreement.',
customStyles: () => ({
fontStyle: 'italic',
color: allAcknowledged() ? '#065f46' : '#92400e',
marginBottom: '12px'
})
});
});
const updateAckCount = () => {
let count = 0;
if (acknowledgmentSection.checkbox('ack1')?.value()) count++;
if (acknowledgmentSection.checkbox('ack2')?.value()) count++;
if (acknowledgmentSection.checkbox('ack3')?.value()) count++;
if (acknowledgmentSection.checkbox('ack4')?.value()) count++;
if (acknowledgmentSection.checkbox('ack5')?.value()) count++;
acknowledgmentCount.set(count);
allAcknowledged.set(count === totalRequired);
};
acknowledgmentSection.addRow(row => {
row.addCheckbox('ack1', {
label: 'I have read and understand the complete policy document',
isRequired: true,
onValueChange: updateAckCount
});
});
acknowledgmentSection.addRow(row => {
row.addCheckbox('ack2', {
label: 'I agree to comply with all requirements outlined in this policy',
isRequired: true,
onValueChange: updateAckCount
});
});
acknowledgmentSection.addRow(row => {
row.addCheckbox('ack3', {
label: 'I understand that violations may result in disciplinary action',
isRequired: true,
onValueChange: updateAckCount
});
});
acknowledgmentSection.addRow(row => {
row.addCheckbox('ack4', {
label: 'I will report any potential violations or concerns to appropriate personnel',
isRequired: true,
onValueChange: updateAckCount
});
});
acknowledgmentSection.addRow(row => {
row.addCheckbox('ack5', {
label: 'I understand I can request clarification from HR at any time',
isRequired: true,
onValueChange: updateAckCount
});
});
// ============================================
// SECTION 5: Employee Information
// ============================================
const employeeSection = form.addSubform('employeeInfo', {
title: 'Employee Information',
isVisible: () => allAcknowledged()
});
employeeSection.addRow(row => {
row.addTextbox('employeeName', {
label: 'Full Legal Name',
placeholder: 'Enter your full name as it appears in HR records',
isRequired: true
}, '1fr');
row.addTextbox('employeeId', {
label: 'Employee ID',
placeholder: 'e.g., EMP-12345'
}, '200px');
});
employeeSection.addRow(row => {
row.addTextbox('department', {
label: 'Department',
placeholder: 'Your department'
}, '1fr');
row.addEmail('employeeEmail', {
label: 'Work Email',
placeholder: 'your.name@company.com',
isRequired: true
}, '1fr');
});
employeeSection.addRow(row => {
row.addDatepicker('acknowledgmentDate', {
label: 'Date of Acknowledgment',
defaultValue: new Date().toISOString().slice(0, 10),
isReadOnly: true
});
});
// ============================================
// SECTION 6: Confirmation Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Acknowledgment Summary',
isVisible: () => allAcknowledged()
});
summarySection.addRow(row => {
row.addTextPanel('summaryText', {
computedValue: () => {
const policy = policySelection.dropdown('policyType')?.value();
const name = employeeSection.textbox('employeeName')?.value();
const policyNames: Record<string, string> = {
'code-of-conduct': 'Code of Conduct',
'data-privacy': 'Data Privacy Policy',
'it-security': 'IT Security Policy',
'anti-harassment': 'Anti-Harassment Policy',
'remote-work': 'Remote Work Policy',
'social-media': 'Social Media Policy'
};
let summary = 'ACKNOWLEDGMENT CONFIRMATION\n';
summary += ''.repeat(35) + '\n\n';
summary += `Policy: ${policyNames[policy || ''] || 'Not selected'}\n`;
summary += `Version: v2.1\n`;
summary += `Employee: ${name || '(Enter your name above)'}\n`;
summary += `Date: ${new Date().toLocaleDateString()}\n\n`;
summary += 'By submitting this form, you confirm that you have read,\n';
summary += 'understood, and agree to comply with the above policy.';
return summary;
},
customStyles: {
backgroundColor: '#d1fae5',
padding: '20px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px',
borderLeft: '4px solid #059669'
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Acknowledgment',
isVisible: () => allAcknowledged()
});
form.configureCompletionScreen({
type: 'text',
title: 'Policy Acknowledged',
message: 'Thank you for acknowledging this policy. A confirmation has been sent to your email address and recorded in the compliance system. Please retain this for your records.'
});
}