components#CardFooter JavaScript Examples
The following examples show how to use
components#CardFooter.
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: wizard.jsx From apps with GNU Affero General Public License v3.0 | 6 votes |
Hi = withSettings(({ settings }) => (
<React.Fragment>
<CardContent>
<p>
<T
t={t}
k="wizard.hi"
link={
<A
key="letUsKnow"
external
href={settings.get('supportEmail')}
>
<T t={t} k="wizard.letUsKnow" key="letUsKnow" />
</A>
}
/>
</p>
</CardContent>
<CardFooter>
<Button type="success" href={`/provider/setup/enter-provider-data`}>
<T t={t} k="wizard.continue" />
</Button>
</CardFooter>
</React.Fragment>
))
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: wizard.jsx From apps with GNU Affero General Public License v3.0 | 6 votes |
Hi = withSettings(({ settings }) => (
<React.Fragment>
<CardContent>
<p>
<T
t={t}
k="wizard.hi"
link={
<A
key="letUsKnow"
external
href={settings.get('supportEmail')}
>
<T t={t} k="wizard.letUsKnow" key="letUsKnow" />
</A>
}
/>
</p>
</CardContent>
<CardFooter>
<Button type="success" href={`/user/setup/enter-contact-data`}>
<T t={t} k="wizard.continue" />
</Button>
</CardFooter>
</React.Fragment>
))
Example #4
Source File: verify.jsx From apps with GNU Affero General Public License v3.0 | 5 votes |
Verify = withSettings(
withActions(({ settings, contactData, contactDataAction }) => {
const [initialized, setInitialized] = useState(false);
useEffect(() => {
if (initialized) return;
contactDataAction();
setInitialized(true);
});
const render = () => (
<React.Fragment>
<CardContent>
<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>
<div className="kip-contact-data-box">
<ul>
<li>
<span>
<T t={t} k="contact-data.email.label" />
</span>{' '}
{contactData.data.email || (
<T t={t} k="contact-data.not-given" />
)}
</li>
</ul>
</div>
<div className="kip-contact-data-links">
<A
className="bulma-button bulma-is-small"
href="/user/setup/enter-contact-data"
>
<T t={t} k="contact-data.change" />
</A>
</div>
</CardContent>
<CardFooter>
<Button type="success" href={`/user/setup/finalize`}>
<T t={t} k="wizard.continue" />
</Button>
</CardFooter>
</React.Fragment>
);
return <WithLoader resources={[contactData]} renderLoaded={render} />;
}, [])
)
Example #5
Source File: settings.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
BaseSettings = ({
type,
settings,
keyPairs,
keyPairsAction,
action,
secondaryAction,
id,
router,
}) => {
let modal;
const [initialized, setInitialized] = useState(false);
const [loggingOut, setLoggingOut] = useState(false);
useEffect(() => {
if (initialized) return;
setInitialized(true);
keyPairsAction();
});
const cancel = () => {
router.navigateToUrl('/mediator/settings');
};
const logOut = () => {
setLoggingOut(true);
const backend = settings.get('backend');
backend.local.deleteAll('mediator::');
router.navigateToUrl('/mediator/logged-out');
};
if (action === 'test-queues') {
modal = <TestQueuesModal keyPairs={keyPairs} />;
} 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>
</Modal>
);
}
return (
<F>
{modal}
<CardContent>
<div className="kip-mediator-settings">
<h2>
<T t={t} k="test-queues.title" />
</h2>
<p>
<T t={t} k="test-queues.text" />
</p>
<div className="kip-buttons">
<Button
type="success"
href="/mediator/settings/test-queues"
>
<T t={t} k="test-queues.button" />
</Button>
</div>
</div>
</CardContent>
<CardFooter>
<div className="kip-buttons">
<Button type="warning" href="/mediator/settings/logout">
<T t={t} k="log-out" />
</Button>
</div>
</CardFooter>
</F>
);
}
Example #6
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}
/>
);
}
)
),
[]
)
Example #7
Source File: provider-data.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
BaseProviderData = ({
embedded,
form: { set, data, error, valid, reset },
}) => {
const [modified, setModified] = useState(false);
const router = useRouter();
const provider = useProvider();
const onSubmit = () => {
if (!valid) return;
provider.data = data;
// we redirect to the 'verify' step
router.navigateToUrl(`/provider/setup/verify`);
};
useEffectOnce(() => {
reset(provider.data || {});
setModified(false);
});
const setAndMarkModified = (key, value) => {
setModified(true);
set(key, value);
};
const controls = (
<React.Fragment>
<ErrorFor error={error} field="name" />
<RetractingLabelInput
value={data.name || ''}
onChange={(value) => setAndMarkModified('name', value)}
label={<T t={t} k="provider-data.name" />}
/>
<ErrorFor error={error} field="street" />
<RetractingLabelInput
value={data.street || ''}
onChange={(value) => setAndMarkModified('street', value)}
label={<T t={t} k="provider-data.street" />}
/>
<ErrorFor error={error} field="zipCode" />
<RetractingLabelInput
value={data.zipCode || ''}
onChange={(value) => setAndMarkModified('zipCode', value)}
label={<T t={t} k="provider-data.zip-code" />}
/>
<ErrorFor error={error} field="city" />
<RetractingLabelInput
value={data.city || ''}
onChange={(value) => setAndMarkModified('city', value)}
label={<T t={t} k="provider-data.city" />}
/>
<ErrorFor error={error} field="website" />
<RetractingLabelInput
value={data.website || ''}
onChange={(value) => setAndMarkModified('website', value)}
label={<T t={t} k="provider-data.website" />}
/>
<ErrorFor error={error} field="description" />
<label htmlFor="description">
<T t={t} k="provider-data.description" />
</label>
<textarea
id="description"
className="bulma-textarea"
value={data.description || ''}
onChange={(e) =>
setAndMarkModified('description', e.target.value)
}
/>
<h3>
<T t={t} k="provider-data.for-mediator" />
</h3>
<ErrorFor error={error} field="phone" />
<RetractingLabelInput
value={data.phone || ''}
onChange={(value) => setAndMarkModified('phone', value)}
label={<T t={t} k="provider-data.phone" />}
/>
<ErrorFor error={error} field="email" />
<RetractingLabelInput
value={data.email || ''}
onChange={(value) => setAndMarkModified('email', value)}
label={<T t={t} k="provider-data.email" />}
/>
<hr />
<ErrorFor error={error} field="code" />
<RetractingLabelInput
value={data.code || ''}
onChange={(value) => setAndMarkModified('code', value)}
description={
<T t={t} k="provider-data.access-code.description" />
}
label={<T t={t} k="provider-data.access-code.label" />}
/>
<hr />
<ul className="kip-properties">
<li className="kip-property">
<Switch
id="accessible"
checked={
data.accessible !== undefined
? data.accessible
: false
}
onChange={(value) =>
setAndMarkModified('accessible', value)
}
>
</Switch>
<label htmlFor="accessible">
<T t={t} k="provider-data.accessible" />
</label>
</li>
</ul>
</React.Fragment>
);
return (
<React.Fragment>
<div className="kip-provider-data">
<FormComponent onSubmit={onSubmit}>
<FieldSet>
<CardContent>{controls}</CardContent>
<CardFooter>
<SubmitField
disabled={!valid || embedded & !modified}
type={'success'}
onClick={onSubmit}
title={
<T
t={t}
k="provider-data.save-and-continue"
/>
}
/>
</CardFooter>
</FieldSet>
</FormComponent>
</div>
</React.Fragment>
);
}
Example #8
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 #9
Source File: accepted-appointment.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
AcceptedInvitation = () => {
const [showDelete, setShowDelete] = useState(false);
const doDelete = () => {
setShowDelete(false);
cancelInvitationAction(acceptedInvitation.data, tokenData.data).then(
() => {
// we reload the appointments
invitationAction();
acceptedInvitationAction();
}
);
};
const {
offer,
invitation: invitationData,
slotData,
} = acceptedInvitation.data;
const currentOffer = offers.find((of) => of.id == offer.id);
let currentSlotData;
if (currentOffer !== undefined)
currentSlotData = currentOffer.slotData.find(
(sl) => sl.id === slotData.id
);
let notice;
let changed = false;
for (const [k, v] of Object.entries(currentOffer)) {
if (
k === 'open' ||
k === 'slotData' ||
k === 'properties' ||
k === 'slots'
)
continue;
if (offer[k] !== v) {
changed = true;
break;
}
}
if (changed)
notice = (
<F>
<Message type="danger">
<T t={t} k="invitation-accepted.changed" />
</Message>
</F>
);
const d = new Date(currentOffer.timestamp);
let modal;
if (showDelete)
return (
<Modal
onSave={doDelete}
onClose={() => setShowDelete(false)}
onCancel={() => setShowDelete(false)}
saveType="danger"
save={<T t={t} k="invitation-accepted.delete.confirm" />}
cancel={<T t={t} k="invitation-accepted.delete.cancel" />}
title={<T t={t} k="invitation-accepted.delete.title" />}
className="kip-appointment-overview"
>
<p>
<T t={t} k="invitation-accepted.delete.notice" />
</p>
</Modal>
);
return (
<F>
<CardContent>
{notice}
<div className="kip-accepted-invitation">
<h2>
<T t={t} k="invitation-accepted.title" />
</h2>
<ProviderDetails data={invitationData.provider} />
<OfferDetails offer={currentOffer} />
<p className="kip-appointment-date">
{d.toLocaleDateString()} ยท{' '}
<u>{d.toLocaleTimeString()}</u>
</p>
<p className="kip-booking-code">
<span>
<T t={t} k={'invitation-accepted.booking-code'} />
</span>
{userSecret.data.slice(0, 4)}
</p>
</div>
</CardContent>
<CardFooter>
<Button type="warning" onClick={() => setShowDelete(true)}>
<T t={t} k="cancel-appointment" />
</Button>
</CardFooter>
</F>
);
}
Example #10
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 #11
Source File: settings.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
Settings = withActions(
withSettings(
withRouter(
({ settings, action, router, userSecret, backupDataAction }) => {
const [loggingOut, setLoggingOut] = useState(false);
let logOutModal;
const cancel = () => {
router.navigateToUrl('/user/settings');
};
const logOut = () => {
setLoggingOut(true);
const backend = settings.get('backend');
// we perform a backup before logging the user out...
backupDataAction(userSecret.data, 'logout').then(() => {
backend.local.deleteAll('user::');
setLoggingOut(false);
router.navigateToUrl('/user/logged-out');
});
};
if (action === 'logout') {
logOutModal = (
<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 />
{userSecret !== undefined && (
<StoreOnline
secret={userSecret.data}
embedded={true}
hideNotice={true}
/>
)}
</Modal>
);
}
return (
<F>
<CardContent>
<div className="kip-user-settings">
{logOutModal}
<h2>
<T t={t} k="user-data.title" />
</h2>
<p>
<T t={t} k="user-data.notice" />
</p>
</div>
</CardContent>
<CardFooter>
<div className="kip-buttons">
<Button
type="warning"
href="/user/settings/logout"
>
<T t={t} k="log-out" />
</Button>
</div>
</CardFooter>
</F>
);
}
)
),
[]
)
Example #12
Source File: contact-data.jsx From apps with GNU Affero General Public License v3.0 | 4 votes |
BaseContactData = ({
form: { set, data, error, valid, reset },
router,
}) => {
const [modified, setModified] = useState(false);
const [initialized, setInitialized] = useState(false);
const user = useUser();
const onSubmit = () => {
if (!valid) return;
user.contactData = data;
// we redirect to the 'verify' step
router.navigateToUrl(`/user/setup/finalize`);
};
useEffect(() => {
if (initialized) return;
setInitialized(true);
setModified(false);
reset(user.contactData || {});
});
const submitting = false;
const setAndMarkModified = (key, value) => {
setModified(true);
set(key, value);
};
const controls = (
<React.Fragment>
<ErrorFor error={error} field="code" />
<RetractingLabelInput
value={data.code || ''}
onChange={(value) => setAndMarkModified('code', value)}
description={
<T t={t} k="contact-data.access-code.description" />
}
label={<T t={t} k="contact-data.access-code.label" />}
/>
</React.Fragment>
);
const redirecting = false;
return (
<React.Fragment>
<div className="kip-cm-contact-data">
<FormComponent onSubmit={onSubmit}>
<FieldSet disabled={submitting}>
{
<React.Fragment>
<CardContent>{controls}</CardContent>
<CardFooter>
<SubmitField
disabled={!valid}
type={'success'}
onClick={onSubmit}
waiting={submitting || redirecting}
title={
redirecting ? (
<T
t={t}
k="contact-data.success"
/>
) : submitting ? (
<T
t={t}
k="contact-data.saving"
/>
) : (
<T
t={t}
k={
'contact-data.save-and-continue'
}
/>
)
}
/>
</CardFooter>
</React.Fragment>
}
</FieldSet>
</FormComponent>
</div>
</React.Fragment>
);
}
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'
)