import PluginModule, { Component } from '@akinon/next/components/plugin-module';
<PluginModule
component={Component.CheckoutGiftPack}
props={{
className: 'flex flex-col w-full mb-4 border border-solid border-gray-400',
translations: {
addGiftPackText: 'Add Gift Pack',
giftPackAdded: 'Gift Pack Added',
removeGiftPackText: 'Remove Gift Pack',
informationText: 'This order will be gift packaged*',
updateNote: 'Update Note',
removeGiftNoteText: 'Remove Gift Note',
charactersLength: 'characters left',
placeholderInput:
'You can leave empty this area. However it will be a gift package without note.',
accordionTitle: 'Gift Note',
warningMessage:
'Make sure that this field is not longer than the character limit.',
save: 'SAVE',
close: 'Close'
},
customUIRender: ({
hasGiftPack,
hasNote,
note,
onAddGiftPack,
onRemoveGiftPack,
onAddNote,
formContent,
translations
}) => (
<div className="custom-gift-pack">
{hasGiftPack ? (
<div className="gift-pack-added p-4 border border-gray-200">
<div className="flex justify-between items-center mb-4">
<span className="font-medium">{translations.giftPackAdded}</span>
<button
onClick={onRemoveGiftPack}
className="text-red-500 hover:text-red-700"
>
{translations.removeGiftPackText}
</button>
</div>
<div className="gift-note-info bg-gray-50 p-3 rounded">
<span className="text-sm text-gray-600">
{translations.informationText}
</span>
{note && <p className="mt-2 text-sm">{note}</p>}
<button
onClick={onAddNote}
className="mt-2 text-blue-500 hover:text-blue-700"
>
{translations.updateNote}
</button>
</div>
{hasNote.state && <div className="mt-4">{formContent}</div>}
</div>
) : (
<button
onClick={onAddGiftPack}
className="w-full p-2 text-center border border-gray-200 hover:bg-gray-50"
>
{translations.addGiftPackText}
</button>
)}
</div>
),
customGiftNoteFormUIRender: ({
register,
errors,
note,
textAreaCount,
onSubmit,
removeNote,
handleSubmit,
translations: formTranslations
}) => (
<form onSubmit={handleSubmit(onSubmit)}>
<textarea
{...register('message')}
value={note}
placeholder={formTranslations.placeholderInput}
/>
{errors.message && <span>{errors.message.message}</span>}
<div className="character-count">
{textAreaCount}/160 {formTranslations.charactersLength}
</div>
<div className="buttons">
<button type="button" onClick={removeNote}>
{formTranslations.removeGiftNoteText}
</button>
<button type="submit">{formTranslations.save}</button>
</div>
</form>
)
}}
/>