Skip to content

Commit

Permalink
feat(backend): WIP - Create Profile Form
Browse files Browse the repository at this point in the history
  • Loading branch information
maikbasel committed Mar 22, 2024
1 parent 4c20a4b commit 13218c3
Show file tree
Hide file tree
Showing 15 changed files with 832 additions and 56 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
"tauri:dev": "cross-env LOCALSTACK_ENDPOINT=http://localhost:4566 npm run tauri dev"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
Expand All @@ -56,6 +59,7 @@
"postcss": "8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.51.1",
"secure-string": "^1.2.1",
"swr": "^2.2.4",
"tailwind-merge": "^2.2.0",
Expand Down
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ heck = "0.4.1"
rust-ini = "0.20.0"
directories = "5.0.1"
aws-sdk-sts = "1.15.0"
log = "0.4.20"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/profile/application/tauri/profile_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn create_profile(
spi: tauri::State<'_, Arc<dyn ProfileDataSPI>>,
profile: Profile,
) -> Result<(), ProfileError> {
log::info!("create_profile: {:?}", profile);
spi.save_profile_data(&profile).map_err(ProfileError::from)
}

Expand All @@ -27,6 +28,7 @@ pub fn edit_profile(
spi: tauri::State<'_, Arc<dyn ProfileDataSPI>>,
profile: Profile,
) -> Result<(), ProfileError> {
log::info!("edit_profile: {:#?}", profile);
spi.update_profile_data(&profile)
.map_err(ProfileError::from)
}
Expand All @@ -37,6 +39,7 @@ pub async fn delete_profile(
spi: tauri::State<'_, Arc<dyn ProfileDataSPI>>,
profile_name: String,
) -> Result<(), ProfileError> {
log::info!("delete_profile: {}", profile_name);
spi.remove_profile_data(&profile_name)
.map_err(ProfileError::from)
}
2 changes: 1 addition & 1 deletion src-tauri/src/profile/core/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl serde::Serialize for Credentials {
.as_ref()
.map(|sec_str| sec_str.unsecure())
.map(std::str::from_utf8)
.map_or("Error transforming secret", |result| match result {
.map(|result| match result {
Ok(sec_str) => sec_str,
Err(e) => panic!("failed to serialize credentials: {}", e),
});
Expand Down
51 changes: 51 additions & 0 deletions src/components/data-table-actions-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use client';

import React from 'react';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Button } from '@/components/ui/button';
import { ChevronDown } from 'lucide-react';

interface DataTableActionsButtonProps<TData> {
selectedRows: TData[];
}

export default function DataTableActionsButton<TData>({
selectedRows,
}: DataTableActionsButtonProps<TData>) {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant='outline'
size='sm'
className='ml-auto hidden h-8 border-dashed lg:flex'
>
<ChevronDown className='mr-2 h-4 w-4' />
Actions
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align='end' className='w-[150px]'>
<DropdownMenuItem>
Create new
</DropdownMenuItem>

Check failure on line 36 in src/components/data-table-actions-button.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/components/data-table-actions-button.tsx#L34-L36

[prettier/prettier] Replace `⏎··········Create·new⏎········` with `Create·new`
<DropdownMenuItem
disabled={!selectedRows || selectedRows?.length !== 1}
>
Edit
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
disabled={!selectedRows || selectedRows?.length === 0}
>
Delete all
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}
141 changes: 141 additions & 0 deletions src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
'use client';

import * as React from 'react';
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';

import { cn } from '@/lib/utils';
import { buttonVariants } from '@/components/ui/button';

const AlertDialog = AlertDialogPrimitive.Root;

const AlertDialogTrigger = AlertDialogPrimitive.Trigger;

const AlertDialogPortal = AlertDialogPrimitive.Portal;

const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Overlay
className={cn(
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className
)}
{...props}
ref={ref}
/>
));
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;

const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
>(({ className, ...props }, ref) => (
<AlertDialogPortal>
<AlertDialogOverlay />
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
className
)}
{...props}
/>
</AlertDialogPortal>
));
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;

const AlertDialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col space-y-2 text-center sm:text-left',
className
)}
{...props}
/>
);
AlertDialogHeader.displayName = 'AlertDialogHeader';

const AlertDialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
className
)}
{...props}
/>
);
AlertDialogFooter.displayName = 'AlertDialogFooter';

const AlertDialogTitle = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Title
ref={ref}
className={cn('text-lg font-semibold', className)}
{...props}
/>
));
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;

const AlertDialogDescription = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Description
ref={ref}
className={cn('text-sm text-muted-foreground', className)}
{...props}
/>
));
AlertDialogDescription.displayName =
AlertDialogPrimitive.Description.displayName;

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn(buttonVariants(), className)}
{...props}
/>
));
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn(
buttonVariants({ variant: 'outline' }),
'mt-2 sm:mt-0',
className
)}
{...props}
/>
));
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;

export {
AlertDialog,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogTrigger,
AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
};
Loading

0 comments on commit 13218c3

Please sign in to comment.