-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(website): update monthly income section on new landing page (#…
…890)
- Loading branch information
Showing
5 changed files
with
103 additions
and
52 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
116 changes: 86 additions & 30 deletions
116
website/src/app/[lang]/[region]/v2/(home)/(components)/income-input.tsx
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,38 +1,94 @@ | ||
'use client'; | ||
|
||
import { ChevronDownIcon } from '@heroicons/react/24/outline'; | ||
import { Button, Popover, PopoverContent, PopoverTrigger, Typography } from '@socialincome/ui'; | ||
import { useI18n } from '@/components/providers/context-providers'; | ||
import { websiteCurrencies } from '@/i18n'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
Input, | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from '@socialincome/ui'; | ||
import classNames from 'classnames'; | ||
import { useEffect } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import * as z from 'zod'; | ||
|
||
export function IncomeInput() { | ||
const choices = ['CHF', 'USD']; | ||
const { currency } = useI18n(); | ||
|
||
const formSchema = z.object({ | ||
value: z.string(), | ||
currency: z.enum(websiteCurrencies as any), | ||
}); | ||
|
||
type FormSchema = z.infer<typeof formSchema>; | ||
const form = useForm<FormSchema>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { value: '5000' as any, currency: currency }, | ||
}); | ||
|
||
useEffect(() => { | ||
form.setValue('currency', currency); | ||
}, [currency]); | ||
|
||
const onSubmit = async (values: FormSchema) => { | ||
alert(`You entered: ${values.value} ${values.currency}`); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col text-white"> | ||
<div className="align-center flex items-center justify-center"> | ||
<Typography weight="medium" className=" mr-1 w-48 py-2 text-right text-7xl opacity-40"> | ||
6 | ||
</Typography> | ||
<Popover openDelay={100} closeDelay={200}> | ||
<PopoverTrigger asChild> | ||
<Button className="flex items-center space-x-1 bg-inherit"> | ||
<Typography>{choices[0]}</Typography> | ||
<ChevronDownIcon className="h-4 w-4" /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent asChild className="bg-popover w-12 p-0"> | ||
<ul className="divide-muted divide-y"> | ||
{choices.map((choice, index) => ( | ||
<li key={index} className="hover:bg-popover-muted py-2 text-center"> | ||
<Typography size="xs">{choice}</Typography> | ||
</li> | ||
))} | ||
</ul> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
<div className="w-64 self-center opacity-40"> | ||
<hr /> | ||
</div> | ||
</div> | ||
<Form {...form}> | ||
<form | ||
className="mx-auto flex max-w-72 items-center justify-center border-b border-white border-opacity-40 pb-3 text-white" | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
> | ||
<FormField | ||
control={form.control} | ||
name="value" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormControl> | ||
<Input | ||
type="number" | ||
className={classNames( | ||
'bg-background w-full border-none text-right text-5xl text-white opacity-40 focus-visible:opacity-100 focus-visible:ring-0', | ||
'[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none', // hide arrows | ||
)} | ||
{...field} | ||
/> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="currency" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<Select onValueChange={field.onChange}> | ||
<FormControl> | ||
<SelectTrigger className="w-20 border-none bg-transparent text-lg text-white focus:ring-0"> | ||
<SelectValue placeholder={field.value} /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{websiteCurrencies.map((currency) => ( | ||
<SelectItem key={currency} value={currency}> | ||
{currency} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
)} | ||
/> | ||
</form> | ||
</Form> | ||
); | ||
} |
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