Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Whatsapp Link #83

Merged
merged 37 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7193352
feat: added confirm remix outlet component
AchmadWahyu Dec 30, 2021
03d7c92
Merge branch 'main' of https://github.com/AchmadWahyu/kelas.rumahberb…
AchmadWahyu Dec 31, 2021
bf09fc8
refactor: move contents from confirm component to component
AchmadWahyu Dec 31, 2021
16dae95
feat: added remix's outlet component to render component
AchmadWahyu Dec 31, 2021
3a68f42
Merge branch 'main' into feature/79-whatsapp-link
Dec 31, 2021
d53a935
Merge branch 'main' of https://github.com/AchmadWahyu/kelas.rumahberb…
AchmadWahyu Dec 31, 2021
043a1ff
feat: write transaction information into database upon form submission
AchmadWahyu Jan 1, 2022
60fe7a0
Merge branch 'feature/79-whatsapp-link' of https://github.com/AchmadW…
AchmadWahyu Jan 1, 2022
066f679
Merge branch 'main' into feature/79-whatsapp-link
zainfathoni Jan 6, 2022
283a8f6
feat: compose whatsapp message
AchmadWahyu Jan 7, 2022
ef048ae
fix: update transaction fields
AchmadWahyu Jan 8, 2022
6824a2c
Merge branch 'main' of https://github.com/AchmadWahyu/kelas.rumahberb…
AchmadWahyu Jan 8, 2022
e15b3c7
feat: added getFirstCourse
AchmadWahyu Jan 8, 2022
0c3d6ee
fix: remove formattedPhoneNumber for authorPhoneNumber
AchmadWahyu Jan 8, 2022
46847b5
feat: added getFirstCourse and debugging action onSubmit
AchmadWahyu Jan 8, 2022
78e66cd
Merge branch 'main' of https://github.com/AchmadWahyu/kelas.rumahberb…
AchmadWahyu Jan 8, 2022
d7f4dc1
Merge branch 'main' into feature/79-whatsapp-link
zainfathoni Jan 9, 2022
4da8947
fix: added asertion to amount and paymentTime
AchmadWahyu Jan 9, 2022
d75f808
feat: set not found error case redirect to dashboard
AchmadWahyu Jan 9, 2022
19084c4
refactor: remove unused type definition and change page name
AchmadWahyu Jan 9, 2022
818f41c
style: remove unused imports
AchmadWahyu Jan 9, 2022
7c9a70a
Merge branch 'feature/79-whatsapp-link' of https://github.com/AchmadW…
AchmadWahyu Jan 9, 2022
eaa9da2
test: decrease code coverage threshold
zainfathoni Jan 9, 2022
7d1e0e2
test: remove routes from code coverage collection for now
zainfathoni Jan 10, 2022
a42c982
Merge branch 'main' into feature/79-whatsapp-link
zainfathoni Feb 25, 2022
b9a6dbf
Merge branch 'main' into pr/AchmadWahyu/83
zainfathoni Feb 25, 2022
bb894a7
feat: add a CTA button in the Purchase index page
zainfathoni Feb 25, 2022
64a377a
fix: strip leading plus from the phone number to comply with WhatsApp
zainfathoni Feb 26, 2022
c51b1cc
feat: move the confirmation dialog into the /verify pathname
zainfathoni Feb 26, 2022
48927d8
refactor: rename the default components
zainfathoni Feb 26, 2022
da22235
feat: load first transaction if exists
zainfathoni Feb 26, 2022
f1ba1ac
fix: use array index instead of .at() due to WebKit limited support
zainfathoni Feb 26, 2022
9de0a63
fix: handle a case where there is no prior transaction
zainfathoni Feb 26, 2022
ed3ddf5
feat: add a CatchBoundary
zainfathoni Feb 26, 2022
1dd7aeb
fix: formatDateTime
zainfathoni Feb 26, 2022
814ad45
Revert "test: remove routes from code coverage collection for now"
zainfathoni Jan 10, 2022
c9941ef
docs: add TODO item for styling the confirmation form
zainfathoni Feb 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions app/routes/dashboard/purchase/confirm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Outlet, redirect } from 'remix'
AchmadWahyu marked this conversation as resolved.
Show resolved Hide resolved
import type { ActionFunction, LoaderFunction } from 'remix'
import type { Subscription, User } from '@prisma/client'
import { validatePhoneNumber, validateRequired } from '~/utils/validators'
import { auth } from '~/services/auth.server'
import { db } from '~/utils/db.server'

interface TransactionFields {
userId: string
subscriptionId: string
bankName: string
bankAccountNumber: string
bankAccountName: string
amount: number
status: string
}

type ActionData = {
formError?: string
fieldErrors?: {
name: string | undefined
phoneNumber: string | undefined
bankName: string | undefined
bankAccountNumber: string | undefined
bankAccountName: string | undefined
amount: number | undefined
paymentTime: string | undefined
}
fields: TransactionFields
}

export const action: ActionFunction = async ({ request }) => {
const user = await auth.isAuthenticated(request, {
failureRedirect: '/login',
})

const form = await request.formData()
const name = form.get('name')
const phoneNumber = form.get('phoneNumber')
const bankName = form.get('bankName')
const bankAccountNumber = form.get('bankAccountNumber')
const bankAccountName = form.get('bankAccountName')
const amount = form.get('amount')
const paymentTime = form.get('paymentTime')

if (
typeof name !== 'string' ||
typeof phoneNumber !== 'string' ||
typeof bankName !== 'string' ||
typeof bankAccountNumber !== 'string' ||
typeof bankAccountName !== 'string' ||
typeof amount !== 'number' ||
typeof paymentTime !== 'string'
) {
return { formError: 'Form not submitted correctly.' }
}

const fieldErrors = {
name: validateRequired('Nama Lengkap', name),
phoneNumber: validatePhoneNumber('Nomor WhatsApp', phoneNumber),
bankName: validateRequired('Nomor WhatsApp', bankName),
bankAccountNumber: validateRequired('Nama Bank', bankAccountNumber),
bankAccountName: validateRequired('Nomor Rekening', bankAccountName),
amount: validateRequired('Nominal', amount),
paymentTime: validateRequired('Nominal', paymentTime),
}

const fields: TransactionFields = {
userId: user.id,
subscriptionId: '123', //should create assign subcription first?
AchmadWahyu marked this conversation as resolved.
Show resolved Hide resolved
bankName,
bankAccountName,
bankAccountNumber,
amount,
status: 'SUBMITTED',
}
if (Object.values(fieldErrors).some(Boolean)) {
return { fieldErrors, fields }
}

const transaction = await db.transaction.create({ data: fields })
}

export default function Confirm() {
return <Outlet />
}
85 changes: 85 additions & 0 deletions app/routes/dashboard/purchase/confirm/$transactionId.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* This example requires Tailwind CSS v2.0+ */
import { Fragment, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { CheckIcon } from '@heroicons/react/outline'

export default function Example() {
const [open, setOpen] = useState(true)

return (
<Transition.Root show={open} as={Fragment}>
<Dialog
as="div"
className="fixed z-10 inset-0 overflow-y-auto"
onClose={setOpen}
>
<div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Dialog.Overlay className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
</Transition.Child>

{/* This element is to trick the browser into centering the modal contents. */}
<span
className="hidden sm:inline-block sm:align-middle sm:h-screen"
aria-hidden="true"
>
&#8203;
</span>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enterTo="opacity-100 translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<div className="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-sm sm:w-full sm:p-6">
<div>
<div className="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100">
<CheckIcon
className="h-6 w-6 text-green-600"
aria-hidden="true"
/>
</div>
<div className="mt-3 text-center sm:mt-5">
<Dialog.Title
as="h3"
className="text-lg leading-6 font-medium text-gray-900"
>
Data transaksi tersimpan
</Dialog.Title>
<div className="mt-2">
<p className="text-sm text-gray-500">
Silakan klik tombol di bawah ini untuk mengirimkan pesan
WhatsApp kepada kami. Setelah itu, tolong lampirkan bukti
transfer berupa foto atau file PDF ke nomor WhatsApp
tersebut. Terima kasih.
</p>
</div>
</div>
</div>
<div className="mt-5 sm:mt-6">
<button
type="button"
className="inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:text-sm"
onClick={() => setOpen(false)}
>
Kirim Pesan WhatsApp
</button>
</div>
</div>
</Transition.Child>
</div>
</Dialog>
</Transition.Root>
)
}