-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
323 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react"; | ||
import { Button, View } from "react-native-ui-lib"; | ||
import { useLocalSearchParams } from "expo-router"; | ||
import Input from "@/components/forms/Input"; | ||
import { api } from "@/utils/api"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
import { z } from "zod"; | ||
|
||
const schema = z.object({ | ||
proof: z.string(), | ||
bankName: z.string(), | ||
bankAccount: z.string(), | ||
bankHolder: z.string(), | ||
}); | ||
|
||
export default function PaymentConfirmScreen() { | ||
const { orderId } = useLocalSearchParams<{ orderId: string }>(); | ||
|
||
const { mutate } = api.order.confirmPayment.useMutation(); | ||
const methods = useForm<z.infer<typeof schema>>({ | ||
resolver: zodResolver(schema), | ||
}); | ||
const { handleSubmit } = methods; | ||
const onSubmit = handleSubmit((data) => { | ||
mutate({ | ||
...data, | ||
orderId, | ||
}); | ||
}); | ||
|
||
return ( | ||
<View bg-white br50 flex padding-s4 className="rounded-b-none"> | ||
<FormProvider {...methods}> | ||
<Input | ||
id="bankName" | ||
label="Nama Bank" | ||
multiline | ||
placeholder="Masukan nama bank" | ||
/> | ||
<Input | ||
id="bankAccount" | ||
label="Nomor Rekening" | ||
multiline | ||
placeholder="Masukan nomor rekening" | ||
/> | ||
<Input | ||
id="bankHolder" | ||
label="Nama Pemilik Rekening" | ||
multiline | ||
placeholder="Masukan nama pemilik rekening" | ||
/> | ||
</FormProvider> | ||
<Button | ||
label="Simpan" | ||
onPress={onSubmit} | ||
bg-primary | ||
br40 | ||
// disabled={isPending} | ||
/> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React from "react"; | ||
import { Alert } from "react-native"; | ||
import { Text, TouchableOpacity, View } from "react-native-ui-lib"; | ||
import * as Clipboard from "expo-clipboard"; | ||
import { Link, useLocalSearchParams } from "expo-router"; | ||
import { api } from "@/utils/api"; | ||
import colors from "@/utils/colors"; | ||
import rupiahFormatter from "@/utils/rupiahFormatter"; | ||
import { Ionicons } from "@expo/vector-icons"; | ||
|
||
const BANK_ACCOUNT = [ | ||
{ | ||
name: "BNI", | ||
number: "12345678910", | ||
}, | ||
{ | ||
name: "BCA", | ||
number: "12345678910", | ||
}, | ||
{ | ||
name: "MANDIRI", | ||
number: "12345678910", | ||
}, | ||
{ | ||
name: "BRI", | ||
number: "12345678910", | ||
}, | ||
]; | ||
|
||
export default function PaymentScreen() { | ||
const { orderId } = useLocalSearchParams<{ orderId: string }>(); | ||
const { data: orders } = api.order.showOrder.useQuery({ | ||
id: orderId, | ||
}); | ||
|
||
return ( | ||
<View bg-white br50 flex padding-s4 className="rounded-b-none"> | ||
<View | ||
paddingV-s2 | ||
paddingH-s4 | ||
br40 | ||
className="border-primary mb-4 space-y-1 border" | ||
> | ||
<Text text80 primary marginB-s1> | ||
Rincian Pembelian | ||
</Text> | ||
<Text text70BO primary> | ||
{orders?.product.name} | ||
</Text> | ||
<Text primary> | ||
Penerima:{" "} | ||
<Text> | ||
{orders?.address.recipient} - {orders?.address.phoneNumber} | ||
</Text> | ||
</Text> | ||
<Text primary> | ||
Alamat:{" "} | ||
<Text> | ||
{orders?.address.address} - {orders?.address.zipCode} | ||
</Text> | ||
</Text> | ||
<Text primary> | ||
Catatan: <Text>{orders?.note ?? "-"}</Text> | ||
</Text> | ||
<Text primary> | ||
Kurir: <Text>{orders?.courier}</Text> | ||
</Text> | ||
<View row spread center> | ||
<Text primary>TOTAL:</Text> | ||
<View flex height={1} bg-black marginH-s2></View> | ||
<Text primary text70BO> | ||
{rupiahFormatter(orders?.totalPrice)} | ||
</Text> | ||
</View> | ||
</View> | ||
<View | ||
paddingV-s2 | ||
paddingH-s4 | ||
br40 | ||
className="border-primary mb-4 space-y-1 border" | ||
> | ||
<Text text80 primary marginB-s1> | ||
Transfer ke Vivat Marketplace | ||
</Text> | ||
{BANK_ACCOUNT.map((bank) => ( | ||
<Text | ||
key={bank.name} | ||
onPress={async () => { | ||
await Clipboard.setStringAsync(bank.number); | ||
Alert.alert("Berhasil menyalin nomor rekening"); | ||
}} | ||
> | ||
{bank.name}: {bank.number} - Vivat Marketplace | ||
</Text> | ||
))} | ||
</View> | ||
<Link href="/payment-confirm" asChild> | ||
<TouchableOpacity | ||
row | ||
spread | ||
paddingV-s2 | ||
paddingH-s4 | ||
br40 | ||
className="border-primary mb-4 border" | ||
> | ||
<Text text70 primary> | ||
Unggah Bukti Pembayaran | ||
</Text> | ||
<Ionicons name="chevron-forward" size={24} color={colors.primary} /> | ||
</TouchableOpacity> | ||
</Link> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
declare module "*.jpg"; | ||
declare module "*.jpeg"; | ||
declare module "*.png"; | ||
declare module "react-native-parallax-scroll-view"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,54 @@ | ||
import { insertOrderParams, orders } from "@vivat/db/schema/orders"; | ||
import { v4 } from "uuid"; | ||
|
||
import { eq } from "@vivat/db"; | ||
import { | ||
insertOrderParams, | ||
orderIdSchema, | ||
orders, | ||
} from "@vivat/db/schema/orders"; | ||
import { createPaymentParams, payments } from "@vivat/db/schema/payments"; | ||
|
||
import { createTRPCRouter, protectedProcedure } from "../trpc"; | ||
|
||
export const orderRouter = createTRPCRouter({ | ||
checkout: protectedProcedure | ||
.input(insertOrderParams) | ||
.mutation(async ({ input, ctx }) => { | ||
return await ctx.db.insert(orders).values(input); | ||
const orderId = v4(); | ||
|
||
await ctx.db.insert(orders).values({ | ||
...input, | ||
id: orderId, | ||
}); | ||
return { orderId }; | ||
}), | ||
showOrder: protectedProcedure | ||
.input(orderIdSchema) | ||
.query(async ({ input, ctx }) => { | ||
return ( | ||
(await ctx.db.query.orders.findFirst({ | ||
with: { | ||
product: true, | ||
address: true, | ||
}, | ||
where: (order, { eq }) => eq(order.id, input.id), | ||
})) ?? null | ||
); | ||
}), | ||
confirmPayment: protectedProcedure | ||
.input(createPaymentParams) | ||
.mutation(async ({ input, ctx }) => { | ||
return await ctx.db.transaction(async (db) => { | ||
await db | ||
.update(payments) | ||
.set(input) | ||
.where(eq(payments.orderId, input.orderId)); | ||
await db | ||
.update(orders) | ||
.set({ | ||
status: "payment", | ||
}) | ||
.where(eq(orders.id, input.orderId)); | ||
}); | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.