Created
November 11, 2020 04:08
-
-
Save rmtuckerphx/4f8f1ff5c76f0d82407fedf9ed869731 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import icon from 'react-icons/lib/go/radio-tower' | |
export default { | |
name: 'transmission', | |
title: 'Transmission', | |
type: 'document', | |
icon, | |
initialValue: { | |
activeDate: (new Date()).toISOString().split('T')[0], | |
message: '. verify ##code## ..', | |
source: 'alpha', | |
}, | |
fieldsets: [ | |
{ name: 'verifyCodes', title: 'Verify Codes' } | |
], | |
fields: [ | |
{ | |
name: 'externalId', | |
title: 'External ID', | |
type: 'number', | |
validation: Rule => Rule.required().integer(), | |
}, | |
{ | |
name: 'source', | |
title: 'Source', | |
type: 'string', | |
validation: Rule => Rule.required(), | |
options: { | |
list: [ | |
{ title: 'Alpha', value: 'alpha' }, | |
], // <-- predefined values | |
layout: 'radio' // <-- defaults to 'dropdown' | |
} | |
}, | |
{ | |
name: 'activeDate', | |
title: 'Active date', | |
type: 'date', | |
validation: Rule => Rule.required() | |
}, | |
{ | |
name: 'otp', | |
title: 'One-Time Pad', | |
type: 'reference', | |
to: [{ type: 'oneTimePad' }], | |
// fieldset: 'verifyCodes', | |
validation: Rule => Rule.required(), | |
options: { | |
}, | |
}, | |
{ | |
name: 'message', | |
title: 'Message', | |
type: 'text', | |
rows: 4, | |
validation: Rule => Rule.required().min(10).max(100).lowercase().custom(message => { | |
if (typeof message === 'undefined') { | |
return true // Allow undefined values | |
} | |
return message.endsWith(' verify ##code## ..') ? true : 'Must end with verify code, a space, and then 2 periods' | |
}) | |
}, | |
{ | |
name: 'manualDecode', | |
title: 'Manual Decode', | |
type: 'reference', | |
to: [{ type: 'verifyCode' }], | |
fieldset: 'verifyCodes', | |
validation: Rule => Rule.required(), | |
options: { | |
filter: ({ document }) => { | |
if (!document.activeDate) { | |
return { | |
filter: 'startDate == $data', | |
params: { | |
data: '1970-01-01' | |
} | |
} | |
} | |
return { | |
filter: 'category == $category && startDate <= $activeDate && endDate >= $activeDate', | |
params: { | |
activeDate: document.activeDate, | |
category: 'decode-manual' | |
} | |
} | |
} | |
}, | |
}, | |
{ | |
name: 'autoDecode', | |
title: 'Auto Decode', | |
type: 'reference', | |
to: [{ type: 'verifyCode' }], | |
fieldset: 'verifyCodes', | |
validation: Rule => Rule.required(), | |
options: { | |
filter: ({ document }) => { | |
if (!document.activeDate) { | |
return { | |
filter: 'startDate == $data', | |
params: { | |
data: '1970-01-01' | |
} | |
} | |
} | |
return { | |
filter: 'category == $category && startDate <= $activeDate && endDate >= $activeDate', | |
params: { | |
activeDate: document.activeDate, | |
category: 'decode-auto' | |
} | |
} | |
} | |
}, | |
}, | |
], | |
preview: { | |
select: { | |
externalId: 'externalId', | |
activeDate: 'activeDate', | |
message: 'message' | |
}, | |
prepare(selection) { | |
const { externalId, activeDate, message } = selection | |
return { | |
title: activeDate, | |
subtitle: externalId, | |
description: message | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment