components#Message JavaScript Examples
The following examples show how to use
components#Message.
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: appointments.jsx From apps with GNU Affero General Public License v3.0 | 6 votes |
ProviderDetails = ({ data }) => {
return (
<div className="kip-provider-details">
<ul>
<li>{data.json.name}</li>
<li>{data.json.street}</li>
<li>{data.json.zipCode}</li>
<li>{data.json.city}</li>
{data.json.accessible && (
<li>
<T t={t} k="provider-details.accessible" />
</li>
)}
</ul>
{data.json.description && (
<Message type="info">{data.json.description}</Message>
)}
</div>
);
}
Example #2
Source File: appointments.jsx From apps with GNU Affero General Public License v3.0 | 6 votes |
InvitationDeleted = ({}) => {
return (
<F>
<Message type="danger">
<T t={t} k="invitation-accepted.deleted" />
</Message>
<CardFooter>
<Button
type="warning"
onClick={() =>
confirmDeletionAction().then(acceptedInvitationAction)
}
>
<T t={t} k="invitation-accepted.confirm-deletion" />
</Button>
</CardFooter>
</F>
);
}
Example #3
Source File: app.jsx From apps with GNU Affero General Public License v3.0 | 6 votes |
render() {
const { settings, route, router, user } = this.props;
const { outdated } = this.state;
const RouteComponent = route.handler.component;
let notice;
if (outdated) {
notice = (
<Message className="kip-outdated-notice" type="warning">
<p>
<T t={t} k="outdated" />
</p>
<Button type="info" onClick={() => location.reload()}>
<T t={t} k="reload" />
</Button>
</Message>
);
}
let content;
if (route.handler.isSimple)
content = this.renderSimple(RouteComponent, route.handler.props);
else content = this.renderFull(RouteComponent, route.handler.props);
return (
<Fragment>
{notice}
{content}
</Fragment>
);
}
Example #4
Source File: index.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
UploadKeyPairsModal = () => {
const mediator = useMediator();
const [invalidFile, setInvalidFile] = useState(false);
const readFile = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function (e) {
const json = JSON.parse(e.target.result);
if (
json.signing === undefined ||
json.encryption === undefined ||
json.provider === undefined
)
setInvalidFile(true);
else mediator.keyPairs = json;
};
reader.readAsBinaryString(file);
};
let notice;
if (invalidFile)
notice = (
<Message type="danger">
<T t={t} k="upload-key-pairs.invalid-file" />
</Message>
);
else notice = <T t={t} k="upload-key-pairs.notice" />;
const footer = (
<Form>
<FieldSet>
<label htmlFor="file-upload" className="custom-file-upload">
<T t={t} k="upload-key-pairs.input" />
<input
id="file-upload"
className="bulma-input"
type="file"
onChange={(e) => readFile(e)}
/>
</label>
</FieldSet>
</Form>
);
return (
<Modal
footer={footer}
className="kip-upload-key-pairs"
title={<T t={t} k="upload-key-pairs.title" />}
>
{notice}
</Modal>
);
}
Example #5
Source File: settings.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
TestQueuesModal = withRouter(
withActions(({ keyPairs, router, testQueues, testQueuesAction }) => {
const [initialized, setInitialized] = useState(false);
useEffect(() => {
if (initialized) return;
setInitialized(true);
testQueuesAction(keyPairs);
});
const readFile = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function (e) {
const json = JSON.parse(e.target.result);
testQueuesAction(keyPairs, json);
};
reader.readAsBinaryString(file);
};
let notice;
const { status } = testQueues;
if (status === 'invalid')
notice = (
<Message type="danger">
<T t={t} k="upload-queues.invalid-file" />
</Message>
);
else if (status === 'valid')
notice = (
<Message type="success">
<T t={t} k="upload-queues.valid-file" />
</Message>
);
else notice = <T t={t} k="upload-queues.notice" />;
const footer = (
<Form>
<FieldSet>
<label htmlFor="file-upload" className="custom-file-upload">
<T t={t} k="upload-queues.input" />
<input
id="file-upload"
disabled={
keyPairs === undefined || keyPairs.data === null
}
className="bulma-input"
type="file"
onChange={(e) => readFile(e)}
/>
</label>
</FieldSet>
</Form>
);
return (
<Modal
footer={footer}
onClose={() => router.navigateToUrl('/mediator/settings')}
className="kip-upload-file"
title={<T t={t} k="upload-queues.title" />}
>
{notice}
</Modal>
);
}, [])
)
Example #6
Source File: index.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
Dashboard = ({
route: {
handler: {
props: { tab, action, secondaryAction, id },
},
},
route,
}) => {
const provider = useProvider();
useInterval(async () => {
const response = await provider.checkData().get();
}, 10000);
let content;
switch (tab) {
case 'settings':
content = <Settings key="settings" action={action} />;
break;
case 'schedule':
content = (
<Schedule
action={action}
route={route}
secondaryAction={secondaryAction}
id={id}
key="schedule"
/>
);
break;
}
let invalidKeyMessage;
if (provider.verifiedData === null) {
invalidKeyMessage = (
<Message waiting type="warning">
<T t={t} k="invalid-key" />
</Message>
);
}
return (
<CenteredCard size="fullwidth" tight>
<CardHeader>
<Tabs>
<Tab active={tab === 'schedule'} href="/provider/schedule">
<T t={t} k="schedule.title" />
</Tab>
<Tab active={tab === 'settings'} href="/provider/settings">
<T t={t} k="settings.title" />
</Tab>
<Tab
last
icon={<Icon icon="sign-out-alt" />}
active={tab === 'log-out'}
href="/provider/settings/logout"
>
<T t={t} k="log-out" />
</Tab>
</Tabs>
</CardHeader>
{invalidKeyMessage}
{content}
</CenteredCard>
);
}
Example #7
Source File: store-secrets.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
BackupDataLink = withSettings(
withActions(
({
onSuccess,
settings,
keyPairs,
downloadText,
providerData,
keyPairsAction,
providerSecret,
providerSecretAction,
backupData,
backupDataAction,
}) => {
const [initialized, setInitialized] = useState(false);
let providerName;
try {
providerName = providerData.data.data.name
.replaceAll(' ', '-')
.replaceAll('.', '-')
.toLowerCase();
} catch (e) {}
useEffect(() => {
if (initialized) return;
setInitialized(true);
keyPairsAction().then((kp) =>
providerSecretAction().then((ps) =>
backupDataAction(kp.data, ps.data)
)
);
});
let blob;
if (backupData !== undefined && backupData.status === 'succeeded') {
blob = new Blob([str2ab(JSON.stringify(backupData.data))], {
type: 'application/octet-stream',
});
}
const title = settings.get('title').toLowerCase();
const dateString = formatDate(new Date());
const filename = `${title}-backup-${dateString}-${providerName}.enc`;
if (blob !== undefined)
return (
<a
onClick={onSuccess}
className="bulma-button bulma-is-success"
download={filename}
href={URL.createObjectURL(blob)}
type="success"
>
{downloadText || (
<T t={t} k="wizard.download-backup-data" />
)}
</a>
);
return (
<Message waiting type="warning">
<T t={t} k="wizard.generating-backup-data" />
</Message>
);
},
[]
)
)
Example #8
Source File: appointments.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
NoInvitations = ({ tokenData }) => {
let createdAt;
if (tokenData.createdAt !== undefined)
createdAt = new Date(tokenData.createdAt);
let content;
// in the first 10 minutes since the creation of the token we show a 'please wait'
// message, as it can take some time for appointments to show up...
if (
createdAt !== undefined &&
new Date(createdAt.getTime() + 1000 * 60 * 10) > new Date()
) {
content = (
<F>
<Message type="success">
<T t={t} k="no-invitations.please-wait" />
</Message>
</F>
);
} else {
content = (
<F>
<Message type="warning">
<T t={t} k="no-invitations.notice" />
</Message>
</F>
);
}
return (
<F>
<CardContent>
<div className="kip-no-invitations">{content}</div>
</CardContent>
<Message type="info">
<ButtonIcon icon="circle-notch fa-spin" />
<T t={t} k="no-invitations.update-notice" />
</Message>
</F>
);
}
Example #9
Source File: stats.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Stats = () => {
const mediator = useMediator();
useEffectOnce(() => {
const params = {
filter: { zipCode: null },
id: 'queues',
type: 'hour',
from: todayPlusN(-1).toISOString(),
to: todayPlusN(1).toISOString(),
};
mediator.stats().get(params);
});
const renderLoaded = () => {
const stats = mediator.stats().result();
const summary = prepareOverallStats(stats);
let content;
if (summary.show === 0) {
content = (
<div className="bulma-column bulma-is-fullwidth-desktop">
<Card size="fullwidth">
<Message type="warning">
<T t={t} k="noData" />
</Message>
</Card>
</div>
);
} else {
content = (
<React.Fragment>
<div className="bulma-column bulma-is-full-desktop">
<Card size="fullwidth" flex>
<CardContent>
<T
key="span"
t={t}
k="dateSpan"
from={
<strong key="s1">
{new Date(
summary.from
).toLocaleString('en-US', opts)}
</strong>
}
to={
<strong key="s2">
{new Date(
summary.to
).toLocaleString('en-US', opts)}
</strong>
}
/>
</CardContent>
</Card>
</div>
<div className="bulma-column bulma-is-one-quarter-desktop">
<SummaryBox
open={summary.open}
booked={summary.booked}
active={summary.active}
/>
</div>
<div className="bulma-column bulma-is-three-quarters-desktop bulma-is-flex">
<Card size="fullwidth" flex>
<CardHeader>
<h2>
<T t={t} k="bookingRate" />
</h2>
</CardHeader>
<CardContent className="kip-cm-overview">
<BarChart
hash={stats.hash}
data={prepareHourlyStats(stats)}
/>
</CardContent>
</Card>
</div>
</React.Fragment>
);
}
return (
<CardContent>
<div className="bulma-columns bulma-is-multiline bulma-is-desktop">
{content}
</div>
</CardContent>
);
};
return (
<WithLoader
resources={[mediator.stats().result()]}
renderLoaded={renderLoaded}
/>
);
}
Example #10
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 #11
Source File: verify.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Verify = () => {
const router = useRouter();
const settings = useSettings();
const provider = useProvider();
const [submitting, setSubmitting] = useState(false);
const [response, setResponse] = useState(null);
const submit = async () => {
if (submitting) return;
setSubmitting(true);
const response = await provider.storeData();
setSubmitting(false);
setResponse(response);
if (response.status === Status.Succeeded)
router.navigateToUrl('/provider/setup/store-secrets');
};
let failedMessage;
let failed;
if (response && response.status === Status.Failed) {
console.log(response);
failed = true;
if (
response.error.error !== undefined &&
response.error.error.code === 401
) {
failedMessage = (
<Message type="danger">
<T t={t} k="wizard.failed.invalid-code" />
</Message>
);
}
}
if (failed && !failedMessage)
failedMessage = (
<Message type="danger">
<T t={t} k="wizard.failed.notice" />
</Message>
);
return (
<>
<CardContent>
{failedMessage}
<p className="kip-verify-notice">
<T
t={t}
k="verify.text"
link={
<A
key="letUsKnow"
external
href={settings.get('supportEmail')}
>
<T t={t} k="wizard.letUsKnow" key="letUsKnow" />
</A>
}
/>
</p>
<ProviderData />
</CardContent>
<CardFooter>
<Button
type={failed ? 'danger' : 'success'}
disabled={submitting}
onClick={submit}
>
<T
t={t}
k={
failed
? 'wizard.failed.title'
: submitting
? 'wizard.please-wait'
: 'wizard.continue'
}
/>
</Button>
</CardFooter>
</>
);
}
Example #12
Source File: appointments.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
InvitationDetails = ({}) => {
const settings = useSettings();
const [confirming, setConfirming] = useState(false);
const [initialized, setInitialized] = useState(false);
useEffect(() => {
if (initialized) return;
setInitialized(true);
toggleOffersAction(null);
});
const toggle = (offer) => {
toggleOffersAction(offer, data.offers);
};
const doConfirmOffers = () => {
const selectedOffers = [];
// we add the selected offers in the order the user chose
for (const offerID of toggleOffers.data) {
const offer = data.offers.find((offer) => offer.id === offerID);
selectedOffers.push(offer);
}
setConfirming(true);
const p = confirmOffersAction(selectedOffers, data, tokenData.data);
p.then(() => {
acceptedInvitationAction();
});
p.finally(() => {
setConfirming(false);
toggleOffersAction(null);
});
};
let content;
const properties = settings.get('appointmentProperties');
// to do: use something better than the index i for the key?
const offers = data.offers
.filter((offer) => offer.slotData.some((sl) => sl.open))
.filter((a) => new Date(a.timestamp) > new Date())
.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp))
.map((offer, i) => {
const d = new Date(offer.timestamp);
const selected = toggleOffers.data.includes(offer.id);
let pref;
if (selected) pref = toggleOffers.data.indexOf(offer.id) + 1;
return (
<tr
key={offer.id}
className={classNames(`kip-pref-${pref}`, {
'kip-selected': selected,
'kip-failed': false,
})}
onClick={() => toggle(offer)}
>
<td>{selected ? pref : '-'}</td>
<td>
{d.toLocaleString('de-DE', {
month: '2-digit',
day: '2-digit',
year: '2-digit',
hour: '2-digit',
minute: '2-digit',
})}
</td>
<td>{formatDuration(offer.duration, settings, t)}</td>
<td>
<PropertyTags appointment={offer} />
</td>
</tr>
);
});
let offerDetails;
if (offers.length === 0)
offerDetails = (
<Message type="warning">
<T t={t} k="no-offers-anymore" />
</Message>
);
else
offerDetails = (
<table className="bulma-table bulma-is-striped bulma-is-fullwidth">
<thead>
<tr>
<th>
<T t={t} k="appointment-preference" />
</th>
<th>
<T t={t} k="appointment-date" />
</th>
<th>
<T t={t} k="appointment-duration" />
</th>
<th>
<T t={t} k="appointment-vaccine" />
</th>
</tr>
</thead>
<tbody>{offers}</tbody>
</table>
);
return (
<F>
<CardContent>
<div className="kip-invitation-details">
<ProviderDetails data={data.provider} />
<p>
<T t={t} k="appointments-notice" />
</p>
{offerDetails}
</div>
</CardContent>
<CardFooter>
<Button
waiting={confirming}
onClick={doConfirmOffers}
disabled={
confirming ||
Object.keys(
toggleOffers.data.filter((id) =>
data.offers.find((of) => of.id === id)
)
).length === 0
}
type="success"
>
<T t={t} k="confirm-appointment" />
</Button>
</CardFooter>
</F>
);
}
Example #13
Source File: finalize.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Finalize = withForm(
withSettings(
withRouter(
({
settings,
router,
form: { set, data, error, valid, reset },
}) => {
const [initialized, setInitialized] = useState(false);
const [modified, setModified] = useState(false);
const [submitting, setSubmitting] = useState(false);
const [tv, setTV] = useState(0);
const user = useUser();
useEffect(async () => {
if (initialized) return;
setInitialized(true);
await user.initialize();
const initialData = {
distance: 5,
};
for (const [k, v] of Object.entries(
t['contact-data'].properties
)) {
for (const [kv, vv] of Object.entries(v.values)) {
initialData[kv] = vv._default;
}
}
reset(user.queueData || initialData);
});
const submit = async () => {
setSubmitting(true);
// we store the queue data
user.queueData = data;
const result = await user.getToken({});
setSubmitting(false);
if (result.status === Status.Failed) return;
await user.backupData();
router.navigateToUrl('/user/setup/store-secrets');
};
const setAndMarkModified = (key, value) => {
setModified(true);
set(key, value);
};
const properties = Object.entries(
t['contact-data'].properties
).map(([k, v]) => {
const items = Object.entries(v.values).map(([kv, vv]) => (
<li key={kv}>
<Switch
id={kv}
checked={data[kv] || false}
onChange={(value) =>
setAndMarkModified(kv, value)
}
>
</Switch>
<label htmlFor={kv}>
<T
t={t}
k={`contact-data.properties.${k}.values.${kv}`}
/>
</label>
</li>
));
return (
<F key={k}>
<h2>
<T
t={t}
k={`contact-data.properties.${k}.title`}
/>
</h2>
<ul className="kip-properties">{items}</ul>
</F>
);
});
const render = () => {
let failedMessage;
let failed;
if (
getToken !== undefined &&
getToken.status === 'failed'
) {
failed = true;
if (getToken.error.error.code === 401) {
failedMessage = (
<Message type="danger">
<T t={t} k="wizard.failed.invalid-code" />
</Message>
);
}
}
if (failed && !failedMessage)
failedMessage = (
<Message type="danger">
<T t={t} k="wizard.failed.notice" />
</Message>
);
return (
<React.Fragment>
<CardContent>
{failedMessage}
<div className="kip-finalize-fields">
<ErrorFor error={error} field="zipCode" />
<RetractingLabelInput
value={data.zipCode || ''}
onChange={(value) =>
setAndMarkModified('zipCode', value)
}
label={
<T
t={t}
k="contact-data.zip-code"
/>
}
/>
<label
className="kip-control-label"
htmlFor="distance"
>
<T
t={t}
k="contact-data.distance.label"
/>
<span className="kip-control-notice">
<T
t={t}
k="contact-data.distance.notice"
/>
</span>
</label>
<ErrorFor error={error} field="distance" />
<RichSelect
id="distance"
value={data.distance || 5}
onChange={(value) =>
setAndMarkModified(
'distance',
value.value
)
}
options={[
{
value: 5,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={5}
/>
),
},
{
value: 10,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={10}
/>
),
},
{
value: 20,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={20}
/>
),
},
{
value: 30,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={30}
/>
),
},
{
value: 40,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={40}
/>
),
},
{
value: 50,
description: (
<T
t={t}
k="contact-data.distance.option"
distance={50}
/>
),
},
]}
/>
{properties}
</div>
</CardContent>
<CardFooter>
<Button
waiting={submitting}
type={failed ? 'danger' : 'success'}
onClick={submit}
disabled={submitting || !valid}
>
<T
t={t}
k={
failed
? 'wizard.failed.title'
: submitting
? 'wizard.please-wait'
: 'wizard.continue'
}
/>
</Button>
</CardFooter>
</React.Fragment>
);
};
return <WithLoader resources={[]} renderLoaded={render} />;
}
)
),
FinalizeForm,
'form'
)