| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- import { Form, Head, Link } from '@inertiajs/react';
- import StoreController from '@/actions/App/Http/Controllers/StoreController';
- import StoreSettingsController from '@/actions/App/Http/Controllers/StoreSettingsController';
- import InputError from '@/components/input-error';
- import StoreNav from '@/components/stores/store-nav';
- import { Button } from '@/components/ui/button';
- import {
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- } from '@/components/ui/card';
- import { Input } from '@/components/ui/input';
- import { Label } from '@/components/ui/label';
- import { dashboard } from '@/routes';
- import type { StoreSummary } from '@/types';
-
- type Settings = {
- whatsapp_number: string | null;
- shipping_west: string;
- shipping_east: string;
- free_shipping_over: string | null;
- };
-
- export default function StoreSettings({
- store,
- settings,
- }: {
- store: StoreSummary;
- settings: Settings;
- }) {
- return (
- <>
- <Head title={`Settings - ${store.name}`} />
-
- <div className="mx-auto w-full max-w-6xl space-y-6 p-4">
- <div>
- <h1 className="text-xl font-semibold">{store.name}</h1>
- <p className="text-sm text-muted-foreground">
- <Link
- href={StoreController.show.url(store.slug)}
- className="hover:underline"
- >
- Back to store
- </Link>
- </p>
- </div>
-
- <StoreNav slug={store.slug} current="settings" />
-
- <Form
- {...StoreSettingsController.update.form(store.slug)}
- options={{ preserveScroll: true }}
- className="max-w-2xl space-y-6"
- >
- {({ processing, errors }) => (
- <>
- <Card>
- <CardHeader>
- <CardTitle>WhatsApp</CardTitle>
- <CardDescription>
- Shoppers see a WhatsApp chat button on
- every page of your store, and on their
- order page. Leave empty to hide it.
- </CardDescription>
- </CardHeader>
- <CardContent className="grid gap-2">
- <Label htmlFor="whatsapp_number">
- WhatsApp number
- </Label>
- <Input
- id="whatsapp_number"
- name="whatsapp_number"
- type="tel"
- inputMode="tel"
- maxLength={30}
- defaultValue={
- settings.whatsapp_number ?? ''
- }
- placeholder="012-345 6789"
- />
- <InputError
- message={errors.whatsapp_number}
- />
- </CardContent>
- </Card>
-
- <Card>
- <CardHeader>
- <CardTitle>Shipping fees</CardTitle>
- <CardDescription>
- Added at checkout, based on the
- shopper’s state.
- </CardDescription>
- </CardHeader>
- <CardContent className="space-y-5">
- <div className="grid gap-5 sm:grid-cols-2">
- <div className="grid gap-2">
- <Label htmlFor="shipping_west">
- Peninsular Malaysia (RM)
- </Label>
- <Input
- id="shipping_west"
- name="shipping_west"
- inputMode="decimal"
- required
- defaultValue={
- settings.shipping_west
- }
- />
- <InputError
- message={errors.shipping_west}
- />
- </div>
- <div className="grid gap-2">
- <Label htmlFor="shipping_east">
- Sabah, Sarawak and Labuan (RM)
- </Label>
- <Input
- id="shipping_east"
- name="shipping_east"
- inputMode="decimal"
- required
- defaultValue={
- settings.shipping_east
- }
- />
- <InputError
- message={errors.shipping_east}
- />
- </div>
- </div>
-
- <div className="grid gap-2 sm:max-w-[calc(50%-0.625rem)]">
- <Label htmlFor="free_shipping_over">
- Free shipping on orders over (RM,
- optional)
- </Label>
- <Input
- id="free_shipping_over"
- name="free_shipping_over"
- inputMode="decimal"
- defaultValue={
- settings.free_shipping_over ??
- ''
- }
- placeholder="100.00"
- aria-describedby="free-help"
- />
- <p
- id="free-help"
- className="text-xs text-muted-foreground"
- >
- Leave empty to always charge
- shipping. Enter 0 to always ship
- free.
- </p>
- <InputError
- message={errors.free_shipping_over}
- />
- </div>
- </CardContent>
- </Card>
-
- <Button
- disabled={processing}
- data-test="save-settings-button"
- >
- Save settings
- </Button>
- </>
- )}
- </Form>
- </div>
- </>
- );
- }
-
- StoreSettings.layout = {
- breadcrumbs: [
- { title: 'Dashboard', href: dashboard() },
- { title: 'Settings', href: '#' },
- ],
- };
|