components#DropdownMenuItem JavaScript Examples
The following examples show how to use
components#DropdownMenuItem.
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: providers.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Providers = ({ action, id }) => {
const router = useRouter();
const mediator = useMediator();
const [view, setView] = useState('pending');
useInterval(async () => {
await mediator.pendingProviders().get();
await mediator.verifiedProviders().get();
}, 10000);
const render = () => {
const providers =
view === 'pending'
? mediator.pendingProviders().result()
: mediator.verifiedProviders().result();
const showProvider = (i) => {
const id = buf2hex(b642buf(i));
router.navigateToUrl(`/mediator/providers/show/${id}`);
};
let modal;
const closeModal = () => router.navigateToUrl('/mediator/providers');
if (action === 'show' && id !== undefined) {
const base64Id = buf2b64(hex2buf(id));
const provider = providers.data.find(
(provider) => provider.data.publicKeys.signing === base64Id
);
const doConfirmProvider = async () => {
const result = await mediator.confirmProvider(provider);
console.log(result);
};
if (provider !== undefined)
modal = (
<Modal
title={<T t={t} k="providers.edit" />}
save={<T t={t} k="providers.confirm" />}
onSave={doConfirmProvider}
saveType="success"
onClose={closeModal}
onCancel={closeModal}
>
<div className="kip-provider-data">
<T t={t} k="providers.confirmText" />
<table className="bulma-table bulma-is-fullwidth bulma-is-striped">
<thead>
<tr>
<th>
<T t={t} k="provider-data.field" />
</th>
<th>
<T t={t} k="provider-data.value" />
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<T t={t} k="provider-data.name" />
</td>
<td>{provider.data.name}</td>
</tr>
<tr>
<td>
<T t={t} k="provider-data.street" />
</td>
<td>{provider.data.street}</td>
</tr>
<tr>
<td>
<T t={t} k="provider-data.city" />
</td>
<td>{provider.data.city}</td>
</tr>
<tr>
<td>
<T
t={t}
k="provider-data.zipCode"
/>
</td>
<td>{provider.data.zipCode}</td>
</tr>
<tr>
<td>
<T t={t} k="provider-data.email" />
</td>
<td>{provider.data.email}</td>
</tr>
<tr>
<td>
<T t={t} k="provider-data.phone" />
</td>
<td>{provider.data.phone}</td>
</tr>
<tr>
<td>
<T
t={t}
k="provider-data.description"
/>
</td>
<td>{provider.data.description}</td>
</tr>
</tbody>
</table>
</div>
</Modal>
);
}
const providerItems = providers.data
.sort(sortProviderByDate)
.map((provider) => (
<ListItem
onClick={() =>
showProvider(provider.data.publicKeys.signing)
}
key={provider.data.publicKeys.signing}
isCard
>
<ListColumn size="md">{provider.data.name}</ListColumn>
<ListColumn size="md">
{provider.data.street} · {provider.data.city}
</ListColumn>
</ListItem>
));
return (
<CardContent>
<div className="kip-providers">
{modal}
<DropdownMenu
title={
<F>
<Icon icon="check-circle" />
<T t={t} k={`providers.${view}`} />
</F>
}
>
<DropdownMenuItem
icon="check-circle"
onClick={() => setView('verified')}
>
<T t={t} k="providers.verified" />
</DropdownMenuItem>
<DropdownMenuItem
icon="exclamation-circle"
onClick={() => setView('pending')}
>
<T t={t} k="providers.pending" />
</DropdownMenuItem>
</DropdownMenu>
<List>
<ListHeader>
<ListColumn size="md">
<T t={t} k="providers.name" />
</ListColumn>
<ListColumn size="md">
<T t={t} k="providers.address" />
</ListColumn>
</ListHeader>
{providerItems}
</List>
</div>
</CardContent>
);
};
return (
<WithLoader
resources={[
mediator.pendingProviders().result(),
mediator.verifiedProviders().result(),
]}
renderLoaded={render}
/>
);
}
Example #2
Source File: schedule.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Schedule = ({ action, secondaryAction, id, route }) => {
const [view, setView] = useState('calendar');
const [lastUpdated, setLastUpdated] = useState(new Date().toLocaleString());
const provider = useProvider();
let startDate;
if (action !== undefined) {
const result = /^(\d{4})-(\d{2})-(\d{2})$/.exec(action);
if (result) {
const [, year, month, day] = result;
startDate = getMonday(
new Date(Number(year), Number(month) - 1, Number(day))
);
}
}
if (startDate === undefined)
startDate = getMonday(new Date().setHours(0, 0, 0, 0));
useEffectOnce(async () => {
const endDate = new Date(startDate);
endDate.setUTCDate(endDate.getUTCDate() + 7);
// we load all the necessary data
const response = await provider
.appointments()
.get({ from: startDate.toISOString(), to: endDate.toISOString() });
console.log(response);
});
if (action === undefined) {
action = formatDate(startDate);
}
const dateString = formatDate(startDate);
const render = () => {
let newAppointmentModal;
let content;
const appointments = provider.appointments().result().data;
switch (view) {
case 'calendar':
content = (
<WeekCalendar
startDate={startDate}
action={action}
secondaryAction={secondaryAction}
id={id}
appointments={appointments}
/>
);
break;
case 'booking-list':
content = (
<AppointmentsList
startDate={startDate}
id={id}
action={action}
secondaryAction={secondaryAction}
appointments={appointments}
/>
);
break;
}
if (secondaryAction === 'new' || secondaryAction === 'edit')
newAppointmentModal = (
<NewAppointment
route={route}
appointments={appointments}
action={action}
id={id}
/>
);
return (
<div className="kip-schedule">
<CardContent>
<div className="kip-non-printable">
{newAppointmentModal}
<Button href={`/provider/schedule/${dateString}/new`}>
<T t={t} k="schedule.appointment.add" />
</Button>
<DropdownMenu
title={
<>
<Icon icon="calendar" />{' '}
<T t={t} k={`schedule.${view}`} />
</>
}
>
<DropdownMenuItem
icon="calendar"
onClick={() => setView('calendar')}
>
<T t={t} k={`schedule.calendar`} />
</DropdownMenuItem>
<DropdownMenuItem
icon="list"
onClick={() => setView('booking-list')}
>
<T t={t} k={`schedule.booking-list`} />
</DropdownMenuItem>
</DropdownMenu>
<hr />
</div>
{content}
</CardContent>
<Message type="info" waiting>
<T t={t} k="schedule.updating" lastUpdated={lastUpdated} />
</Message>
</div>
);
};
// we wait until all resources have been loaded before we display the form
return (
<WithLoader
resources={[provider.appointments().result()]}
renderLoaded={render}
/>
);
}
Example #3
Source File: settings.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Settings = withActions(
withRouter(
withSettings(
({
action,
type,
settings,
keys,
keysAction,
keyPairs,
keyPairsAction,
providerSecret,
providerSecretAction,
backupData,
backupDataAction,
providerData,
providerDataAction,
verifiedProviderData,
verifiedProviderDataAction,
router,
}) => {
const [deleting, setDeleting] = useState(false);
const [loggingOut, setLoggingOut] = useState(false);
const [initialized, setInitialized] = useState(false);
const [view, setView] = useState('verified');
// we load all the resources we need
useEffect(() => {
if (initialized) return;
keysAction();
verifiedProviderDataAction();
providerDataAction();
setInitialized(true);
});
let modal;
const title = settings.get('title').toLowerCase();
const cancel = () => {
router.navigateToUrl('/provider/settings');
};
const deleteData = () => {
setDeleting(true);
const backend = settings.get('backend');
backend.local.deleteAll('provider::');
setDeleting(false);
router.navigateToUrl('/provider/deleted');
};
const logOut = () => {
setLoggingOut(true);
const kpa = keyPairsAction('logoutKeyPairs');
kpa.then((kp) => {
const psa = providerSecretAction(
undefined,
'logoutProviderSecret'
);
psa.then((ps) => {
// we give the backup data action a different name to avoid it being rejected
// in case there's already a backup in progress... It will still be queued
// up to ensure no conflicts can occur.
const ba = backupDataAction(
kp.data,
ps.data,
'logout'
);
ba.then(() => {
const backend = settings.get('backend');
backend.local.deleteAll('provider::');
router.navigateToUrl('/provider/logged-out');
});
ba.catch(() => setLoggingOut(false));
});
psa.catch(() => setLoggingOut(false));
});
kpa.catch(() => setLoggingOut(false));
};
if (action === 'backup') {
modal = (
<Modal
onClose={cancel}
save="Sicherungsdatei herunterladen"
title={<T t={t} k="backup-modal.title" />}
onCancel={cancel}
cancel={<T t={t} k="backup-modal.close" />}
saveType="success"
>
<p>
<T t={t} k="backup-modal.text" />
</p>
<hr />
<DataSecret
secret={providerSecret.data}
embedded={true}
hideNotice={true}
/>
<Button
style={{ marginRight: '1em' }}
type="success"
onClick={() =>
copyToClipboard(providerSecret.data)
}
>
Datenschlüssel kopieren
</Button>
<BackupDataLink
downloadText={
<T t={t} k="backup-modal.download-backup" />
}
onSuccess={cancel}
/>
</Modal>
);
} else if (action === 'delete') {
modal = (
<Modal
onClose={cancel}
save={<T t={t} k="delete" />}
disabled={deleting}
waiting={deleting}
title={<T t={t} k="delete-modal.title" />}
onCancel={cancel}
onSave={deleteData}
saveType="danger"
>
<p>
<T
t={t}
k={
deleting
? 'delete-modal.deleting-text'
: 'delete-modal.text'
}
/>
</p>
</Modal>
);
} else if (action === 'logout') {
modal = (
<Modal
onClose={cancel}
save={<T t={t} k="log-out" />}
disabled={loggingOut}
waiting={loggingOut}
title={<T t={t} k="log-out-modal.title" />}
onCancel={cancel}
onSave={logOut}
saveType="warning"
>
<p>
<T
t={t}
k={
loggingOut
? 'log-out-modal.logging-out'
: 'log-out-modal.text'
}
/>
</p>
<hr />
<DataSecret
secret={providerSecret.data}
embedded={true}
hideNotice={true}
/>
<Button
style={{ marginRight: '1em' }}
type="success"
onClick={() =>
copyToClipboard(providerSecret.data)
}
>
Datenschlüssel kopieren
</Button>
<BackupDataLink
downloadText={
<T t={t} k="backup-modal.download-backup" />
}
/>
</Modal>
);
}
const render = () => {
return (
<div className="kip-provider-settings">
{modal}
<CardContent>
<h2>
<T t={t} k="provider-data.title" />
</h2>
<p style={{ marginBottom: '1em' }}>
<T
t={t}
k="provider-data.verified-vs-unverifired-desc"
/>
</p>
<DropdownMenu
title={
<F>
<Icon icon="calendar" />{' '}
<T t={t} k={`settings.${view}`} />
</F>
}
>
<DropdownMenuItem
icon="calendar"
onClick={() => setView('verified')}
>
<T t={t} k={`settings.verified`} />
</DropdownMenuItem>
<DropdownMenuItem
icon="list"
onClick={() => setView('local')}
>
<T t={t} k={`settings.local`} />
</DropdownMenuItem>
</DropdownMenu>
<ProviderData
providerData={
view === 'verified'
? verifiedProviderData
: providerData
}
verified={view === 'verified'}
/>
</CardContent>
<CardFooter>
<div className="kip-buttons">
<Button
type="success"
href="/provider/settings/backup"
>
<T t={t} k="backup" />
</Button>
<Button
type="warning"
href="/provider/settings/logout"
>
<T t={t} k="log-out" />
</Button>
{false && (
<Button
type="danger"
href="/provider/settings/delete"
>
<T t={t} k="delete" />
</Button>
)}
</div>
</CardFooter>
</div>
);
};
// we wait until all resources have been loaded before we display the form
return (
<WithLoader
resources={[
keyPairs,
providerData,
verifiedProviderData,
]}
renderLoaded={render}
/>
);
}
)
),
[]
)