Skip to content

Commit

Permalink
fix(documents): umlaute in file names
Browse files Browse the repository at this point in the history
  • Loading branch information
JappyMondo committed Oct 19, 2024
1 parent 12e9865 commit e217c6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
25 changes: 14 additions & 11 deletions src/components/pilot-id/documents/pilot-id-documents-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ export async function PilotIdDocumentsCard() {
<Card className="col-span-1 lg:col-span-5">
<CardContent className="p-4 space-y-6">
<div className="space-y-1">
<div className="mb-4">
<h2 className="text-lg font-semibold">Documents</h2>
<p className="text-gray-500 dark:text-gray-400">
Legal, Insurance and other Documents.
<br />
<small>(These are only visible to yourself)</small>
</p>
<div className="mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between">
<div>
<h2 className="text-lg font-semibold">Documents</h2>
<p className="text-gray-500 dark:text-gray-400">
Legal, Insurance and other Documents.
<br />
<small>(These are only visible to yourself)</small>
</p>
</div>

{/* Upload documents button adjusted for responsiveness */}
<div className="mt-4 sm:mt-0">
<PilotIdDocumentsUploadButton />
</div>
</div>

<div className="flex flex-col space-y-4">
Expand All @@ -63,10 +70,6 @@ export async function PilotIdDocumentsCard() {
))
)}
</div>

<div className="flex items-center space-x-4 pt-4">
<PilotIdDocumentsUploadButton />
</div>
</div>
</CardContent>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { uploadFileAction } from "@/lib/file-upload.action";
import { getSupabaseServerClient } from "@/lib/supabase.server";
import { Document } from "@/types/supabase-custom";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";

async function createFileMetaData(file: File, fileId: string) {
async function createFileMetaData(
file: File,
fileNameUTF8: string,
fileId: string
) {
const supabase = getSupabaseServerClient();

const {
Expand All @@ -20,9 +23,9 @@ async function createFileMetaData(file: File, fileId: string) {
}

const meta: Omit<Document, "id" | "created_at"> = {
original_file_name: file.name,
original_file_name: fileNameUTF8,
path: fileId,
name: file.name,
name: fileNameUTF8,
user_id: user.id,
category: "miscellaneous",
};
Expand All @@ -42,7 +45,7 @@ async function createFileMetaData(file: File, fileId: string) {
return { data };
}

async function uploadDocument(file: File) {
async function uploadDocument(file: File, fileNameUTF8: string) {
const { error: uploadError, fullFilePath } = await uploadFileAction({
bucketName: "documents",
file,
Expand All @@ -56,6 +59,7 @@ async function uploadDocument(file: File) {

const { error: metaError, data } = await createFileMetaData(
file,
fileNameUTF8,
fullFilePath!
);

Expand Down Expand Up @@ -99,6 +103,7 @@ async function getShareHandleOfCurrentUser() {

export async function uploadDocumentFormAction(formData: FormData) {
const file = formData.get("file") as File;
const fileNameUTF8 = formData.get("fileNameUTF8") as string;

const { error: shareHandleError, shareHandle } =
await getShareHandleOfCurrentUser();
Expand All @@ -107,7 +112,7 @@ export async function uploadDocumentFormAction(formData: FormData) {
return { error: shareHandleError };
}

const { error: uploadError, meta } = await uploadDocument(file);
const { error: uploadError, meta } = await uploadDocument(file, fileNameUTF8);

if (uploadError) {
return { error: uploadError };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function PilotIdDocumentsUploadButton(props: Props) {

const onSubmit = useCallback(async (formData: FormData) => {
startUploadTransition(async () => {
const file = formData.get("file") as any;
formData.set("fileNameUTF8", file.name);
const { error, document } = await uploadDocumentFormAction(formData);

if (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/pilot-id/pilot-id-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export async function PilotIdCard(props: {
</p>
</div>

<div className="flex items-center justify-between">
<div className="flex flex-col sm:flex-row sm:items-start justify-between space-y-4 sm:space-y-0">
<div className="space-y-2">
{pilot.contact_phone && (
<div className="flex items-center space-x-4">
Expand All @@ -203,10 +203,10 @@ export async function PilotIdCard(props: {
)}
</div>

<div className="rounded-lg overflow-hidden">
<div className="rounded-lg overflow-hidden self-center sm:self-auto">
<PilotShareQRCode
shareHandle={pilot.share_handle ?? ""}
width={100}
width={200}
/>
</div>
</div>
Expand Down

0 comments on commit e217c6e

Please sign in to comment.