Skip to content

Commit

Permalink
Merge pull request #3 from upperdo/develop
Browse files Browse the repository at this point in the history
feat: FunctionService & Settings route
  • Loading branch information
acidlake committed Oct 24, 2023
2 parents db0d12a + 40f311b commit 59a7ef1
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 25 deletions.
55 changes: 51 additions & 4 deletions src/lib/common/constants/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,56 @@ type SEO = {
}
}

export type {
AccountData, SessionData, CoreData,
LanguageListData, DocumentListData,
export enum ExecutionTriggers {
http,
schedule,
event
}

export enum ExecutionStatus {
processing,
completed,
failed
}


type CommonExecutionProperties<T> = {
$id: string
$createdAt: string
$updatedAt: string
$permissions: string[]
funtionId?: string
$trigger?: ExecutionTriggers
status: ExecutionStatus
requestMethod: string
requestPath: string
requestHeaders: ExtraData[]
responseStatusCode: number
responseBody: T
responseHeaders: ExtraData[]
logs: string
errors: string
duration: number
}

type ExecutionListData<T> = {
total: number
executions: T[]
}

type ExecutionPlaceHolderData = {

}

type ExecutionData<T> = {

} & CommonExecutionProperties<T>;

export type {
AccountData, SessionData, CoreData,
LanguageListData, DocumentListData,
UserData, GlobalDocumentProperties, DocumentData,
SEO
SEO, CommonExecutionProperties, ExecutionListData,
ExecutionPlaceHolderData,
ExecutionData, ExtraData
};
3 changes: 2 additions & 1 deletion src/lib/common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { BrowserRedirectTo } from "./redirect";
export { CheckIfUserIsLoggedIn } from "./checkIfUserIsLoggedIn";
export { languageSwitcherFunc } from "./languageSwitcherFunc";
export { cn, flyAndScale } from "./shadcn-utility";
export { cn, flyAndScale } from "./shadcn-utility";
export { parseEnumValue } from "./parseEnumValue";
18 changes: 18 additions & 0 deletions src/lib/common/utils/parseEnumValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @name parseEnumValue
* @param enumType
* @param value
*
* @description Function that parse the value of a given enum type
* @returns value of the enumType
*/
export const parseEnumValue = (enumType: any, value: any): any | null =>{
if(value){
for (const key in enumType){
if(enumType[key] === value) {
return value;
}
}
}
return null;
}
3 changes: 2 additions & 1 deletion src/lib/features/dashboard/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { default as DashboardMainNav } from "./main-nav.svelte";
export { default as Overview } from "./overview.svelte";
export { default as RecentSales } from "./recent-sales.svelte";
export { default as Search } from "./search.svelte";
export { default as UserNav } from "./user-nav.svelte";
export { default as UserNav } from "./user-nav.svelte";
export { default as SidebarNav } from "./sidebar-nav.svelte";
8 changes: 4 additions & 4 deletions src/lib/features/dashboard/widgets/main-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

<nav class={cn("flex items-center space-x-4 lg:space-x-6", className)}>
<a
href="/examples/dashboard"
href="/dashboard"
class="text-sm font-medium transition-colors hover:text-primary"
>
Overview
</a>

<a
href="/examples/dashboard"
href="/dashboard"
class="text-sm font-medium text-muted-foreground transition-colors hover:text-primary"
>
Customers
</a>
<a
href="/examples/dashboard"
href="/dashboard"
class="text-sm font-medium text-muted-foreground transition-colors hover:text-primary"
>
Products
</a>
<a
href="/examples/dashboard"
href="/dashboard"
class="text-sm font-medium text-muted-foreground transition-colors hover:text-primary"
>
Settings
Expand Down
30 changes: 30 additions & 0 deletions src/lib/features/dashboard/widgets/sidebar-nav.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import { cn } from "$lib/common/utils";
import { page } from "$app/stores";
import Button from "$lib/ui/components/button/button.svelte";
let className: string | undefined | null = undefined;
export let items: { href: string; title: string }[];
export { className as class };
</script>

<nav
class={cn(
"flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1",
className
)}
>
{#each items as item}
<Button
href={item.href}
variant="ghost"
class={cn(
$page.url.pathname === item.href
? "bg-muted hover:bg-muted"
: "hover:bg-transparent hover:underline",
"justify-start"
)}
>
{item.title}
</Button>
{/each}
</nav>
12 changes: 5 additions & 7 deletions src/lib/features/dashboard/widgets/user-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@
<DropdownMenu.Separator />
<DropdownMenu.Group>
<DropdownMenu.Item>
Profile
<DropdownMenu.Shortcut>⇧⌘P</DropdownMenu.Shortcut>
<a href="/settings/profile">
Profile
</a>
</DropdownMenu.Item>
<DropdownMenu.Item>
Billing
<DropdownMenu.Shortcut>⌘B</DropdownMenu.Shortcut>
<a href="/settings/account">Account</a>
</DropdownMenu.Item>
<DropdownMenu.Item>
Settings
<DropdownMenu.Shortcut>⌘S</DropdownMenu.Shortcut>
<a href="/settings/security">Security</a>
</DropdownMenu.Item>
<DropdownMenu.Item>New Team</DropdownMenu.Item>
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.Item on:click={logout}>
Expand Down
102 changes: 102 additions & 0 deletions src/lib/features/settings/widgets/forms/account-form.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<script lang="ts" context="module">
import { z } from "zod";
const languages = {
en: "English",
fr: "French",
de: "German",
es: "Spanish",
pt: "Portuguese",
ru: "Russian",
ja: "Japanese",
ko: "Korean",
zh: "Chinese"
} as const;
type Language = keyof typeof languages;
export const accountFormSchema = z.object({
name: z
.string({
required_error: "Required."
})
.min(2, "Name must be at least 2 characters.")
.max(30, "Name must not be longer than 30 characters"),
email: z
.string({
required_error: "Required."
})
.email()
.min(2, "Email must be at least 2 characters.")
.max(30, "Email must not be longer than 30 characters"),
// Hack: https://github.com/colinhacks/zod/issues/2280
language: z.enum(Object.keys(languages) as [Language, ...Language[]])
});
export type AccountFormSchema = typeof accountFormSchema;
</script>

<script lang="ts">
import * as Form from "$lib/ui/components/form";
import type { SuperValidated } from "sveltekit-superforms";
import { cn } from "$lib/common/utils";
export let data: SuperValidated<AccountFormSchema>;
</script>

<Form.Root
method="POST"
class="space-y-8"
let:config
schema={accountFormSchema}
form={data}
debug={true}
>
<Form.Item>
<Form.Field name="name" {config}>
<Form.Label>Name</Form.Label>
<Form.Input placeholder="Your name" />
<Form.Description>
This is the name that will be displayed on your profile and in
emails.
</Form.Description>
<Form.Validation />
</Form.Field>
<Form.Field name="email" {config}>
<Form.Label>Email</Form.Label>
<Form.Input placeholder="example@example.com" />
<Form.Description>
This is the name that will be displayed on your profile and in
emails.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Item>
<Form.Field {config} name="language" let:attrs>
{@const { value } = attrs.input}
<Form.Label>Language</Form.Label>
<Form.Select selected={{ value, label: languages[value] }}>
<Form.SelectTrigger
placeholder="Select language"
class={cn(
"w-[200px] justify-between",
!attrs.input.value && "text-muted-foreground"
)}
/>
<Form.SelectContent class="h-52 overflow-y-auto">
{#each Object.entries(languages) as [value, lang]}
<Form.SelectItem {value}>
{lang}
</Form.SelectItem>
{/each}
</Form.SelectContent>
</Form.Select>
<Form.Description>
This is the language that will be used in the dashboard.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Button>Update account</Form.Button>
</Form.Root>
98 changes: 98 additions & 0 deletions src/lib/features/settings/widgets/profile-form.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<script lang="ts" context="module">
import { z } from "zod";
export const profileFormSchema = z.object({
username: z
.string()
.min(2, "Username must be at least 2 characters.")
.max(30, "Username must not be longer than 30 characters"),
email: z
.string({ required_error: "Please select an email to display" })
.email(),
bio: z.string().min(4).max(160).default("I own a computer."),
website: z
.string()
.url({ message: "Please enter a valid URL." })
.default("https://shadcn-svelte.com")
});
export type ProfileFormSchema = typeof profileFormSchema;
</script>

<script lang="ts">
import * as Form from "$lib/ui/components/form";
import type { SuperValidated } from "sveltekit-superforms";
export let data: SuperValidated<ProfileFormSchema>;
</script>

<Form.Root
form={data}
schema={profileFormSchema}
let:config
method="POST"
class="space-y-8"
debug={true}
>
<Form.Item>
<Form.Field {config} name="username">
<Form.Label>Username</Form.Label>
<Form.Input placeholder="@shadcn" />
<Form.Description>
This is your public display name. It can be your real name or a
pseudonym. You can only change this once every 30 days.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Item>
<Form.Field {config} name="email">
<Form.Label>Email</Form.Label>
<Form.Select>
<Form.SelectTrigger
placeholder="Select a verified email to display"
/>
<Form.SelectContent>
<Form.SelectItem value="m@example.com" label="m@example.com"
>m@example.com
</Form.SelectItem>
<Form.SelectItem value="m@google.com" label="m@google.com"
>m@google.com
</Form.SelectItem>
<Form.SelectItem value="m@support.com" label="m@support.com"
>m@support.com
</Form.SelectItem>
</Form.SelectContent>
</Form.Select>
<Form.Description>
You can manage verified email addresses in your <a
href="/examples/forms">email settings</a
>.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Item>
<Form.Field {config} name="bio">
<Form.Label>Bio</Form.Label>
<Form.Textarea
placeholder="Tell us a little bit about yourself"
class="resize-none"
/>
<Form.Description>
You can <span>@mention</span> other users and organizations to link
to them.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Item>
<Form.Field {config} name="website">
<Form.Label>Website</Form.Label>
<Form.Input />
<Form.Description>
Your personal website, blog, or portfolio.
</Form.Description>
<Form.Validation />
</Form.Field>
</Form.Item>
<Form.Button>Update profile</Form.Button>
</Form.Root>
Loading

0 comments on commit 59a7ef1

Please sign in to comment.