Implementing a send invitation action
This commit is contained in:
parent
5893a2e665
commit
39362db69d
|
@ -22,13 +22,58 @@ import { update } from '~/lib/update';
|
|||
import { replicationDocument } from '~/lib/replication-document';
|
||||
import { get } from '~/lib/get';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { sendInvitation } from '~/routes/user/[id]';
|
||||
|
||||
import { createServerAction$ } from 'solid-start/server';
|
||||
import { readConfig } from '~/server-only-lib/read-config';
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { resolve } from 'path';
|
||||
import hbs from 'nodemailer-express-handlebars';
|
||||
|
||||
|
||||
interface Props {
|
||||
values?: () => any;
|
||||
}
|
||||
|
||||
const User: Component<Props> = (props) => {
|
||||
|
||||
const [sendingInvitation, sendInvitation] = createServerAction$(
|
||||
async (args: {
|
||||
id: string;
|
||||
mail: string;
|
||||
webInvitation: string;
|
||||
appInvitation: string;
|
||||
}) => {
|
||||
const { id, mail, webInvitation, appInvitation } = args;
|
||||
const { credentials, mailer } = readConfig();
|
||||
const transporter = createTransport(mailer);
|
||||
|
||||
const handlebarOptions = {
|
||||
viewEngine: {
|
||||
partialsDir: resolve('src/mail-template/'),
|
||||
defaultLayout: false,
|
||||
},
|
||||
viewPath: resolve('src/mail-template/'),
|
||||
};
|
||||
transporter.use('compile', hbs(handlebarOptions));
|
||||
|
||||
const code = [...Array(6)].map((_) => (Math.random() * 10) | 0).join('');
|
||||
|
||||
const mailOptions = {
|
||||
from: '"Dyomedea app" <app@dyomedea.com>', // sender address
|
||||
to: mail, // list of receivers
|
||||
subject: "Invitation à configurer l'application Dyomedea.",
|
||||
template: 'invitation', // the name of the template file i.e email.handlebars
|
||||
context: {
|
||||
id,
|
||||
webInvitation,
|
||||
appInvitation,
|
||||
},
|
||||
};
|
||||
|
||||
await transporter.sendMail(mailOptions);
|
||||
}
|
||||
);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [progress, setProgress] = createSignal(-1);
|
||||
|
|
|
@ -3,49 +3,7 @@ import User from '~/components/user';
|
|||
import { createEffect, createSignal, Show } from 'solid-js';
|
||||
import { adminCredentials, CheckCredentials } from '~/components/credentials';
|
||||
import { get } from '~/lib/get';
|
||||
import { createServerAction$ } from 'solid-start/server';
|
||||
import { readConfig } from '~/server-only-lib/read-config';
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { resolve } from 'path';
|
||||
import hbs from 'nodemailer-express-handlebars';
|
||||
|
||||
export const [sendingInvitation, sendInvitation] = createServerAction$(
|
||||
async (args: {
|
||||
id: string;
|
||||
mail: string;
|
||||
webInvitation: string;
|
||||
appInvitation: string;
|
||||
}) => {
|
||||
const { id, mail, webInvitation, appInvitation } = args;
|
||||
const { credentials, mailer } = readConfig();
|
||||
const transporter = createTransport(mailer);
|
||||
|
||||
const handlebarOptions = {
|
||||
viewEngine: {
|
||||
partialsDir: resolve('src/mail-template/'),
|
||||
defaultLayout: false,
|
||||
},
|
||||
viewPath: resolve('src/mail-template/'),
|
||||
};
|
||||
transporter.use('compile', hbs(handlebarOptions));
|
||||
|
||||
const code = [...Array(6)].map((_) => (Math.random() * 10) | 0).join('');
|
||||
|
||||
const mailOptions = {
|
||||
from: '"Dyomedea app" <app@dyomedea.com>', // sender address
|
||||
to: mail, // list of receivers
|
||||
subject: "Invitation à configurer l'application Dyomedea.",
|
||||
template: 'invitation', // the name of the template file i.e email.handlebars
|
||||
context: {
|
||||
id,
|
||||
webInvitation,
|
||||
appInvitation,
|
||||
},
|
||||
};
|
||||
|
||||
await transporter.sendMail(mailOptions);
|
||||
}
|
||||
);
|
||||
|
||||
export default () => {
|
||||
const { id } = useParams();
|
||||
|
|
Loading…
Reference in New Issue