@airtable/blocks/ui#ChoiceToken JavaScript Examples
The following examples show how to use
@airtable/blocks/ui#ChoiceToken.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: send-messages.js From neighbor-express with MIT License | 4 votes |
export function SendMessagesStep({ previousStep }) {
const [completed, setCompleted] = useState(false);
const [sending, setSending] = useState(false);
const [progress, setProgress] = useState(0);
const messagesTable = useBase().getTable("Messages");
const statusField = messagesTable.getFieldByName("Status");
const queuedOption = statusField.options.choices.find(
(c) => c.name == "Queued"
);
const messagesToSend = useRecords(messagesTable).filter(
(m) => m.getCellValue("Status").name === "Queued"
);
async function sendMessages() {
setCompleted(false);
setSending(true);
const total = messagesToSend.length;
let i = 0;
for (const messageToSend of messagesToSend) {
const response = await sendMessage(messageToSend);
if (response.status === 202) {
messagesTable.updateRecordAsync(messageToSend.id, {
Status: { name: "Sent" },
"Sent Time": new Date(),
});
} else {
messagesTable.updateRecordAsync(messageToSend.id, {
Status: { name: "Errored" },
});
}
i += 1;
setProgress(i / total);
}
setSending(false);
setCompleted(true);
}
async function goBack() {
// Clear any non-persistent data before leaving
setCompleted(false);
setSending(false);
setProgress(0);
previousStep();
}
return (
<Box>
<h2> Step 2: Send emails </h2>
{(sending || completed) && <ProgressBar progress={progress} />}
{completed && <p> Successfully sent all messages </p>}
{messagesToSend.length === 0 ? (
<p>
{" "}
There are no messages with status{" "}
<ChoiceToken choice={queuedOption} marginRight={1} />{" "}
</p>
) : (
<>
<Box
margin={2}
display="flex"
flexDirection="row"
justifyContent="flex-start"
alignItems="center"
>
<Text>
{" "}
The following {messagesToSend.length} messages will be sent:
</Text>
<Button
marginX={2}
variant="primary"
onClick={sendMessages}
disabled={sending}
>
Send All Messages
</Button>
</Box>
<Box height="300px" border="thick" backgroundColor="lightGray1">
<RecordCardList
records={messagesToSend}
fields={["Email type", "Recipient", "Delivery"].map((f) =>
messagesTable.getFieldByName(f)
)}
/>
</Box>
</>
)}
<Button onClick={goBack}> Go Back </Button>
</Box>
);
}