@@ -4,6 +4,7 @@ import { ChangeEventHandler, useCallback, useEffect, useState } from "react"
4
4
import { Button , Col , Form , InputGroup , Row , Spinner } from "../bootstrap"
5
5
import { AttachmentInfo , UseDraftTestimonyAttachment } from "../db"
6
6
import { External } from "../links"
7
+ import { useTranslation } from "next-i18next"
7
8
8
9
export function Attachment ( {
9
10
attachment,
@@ -65,11 +66,10 @@ const Label = ({
65
66
} : {
66
67
attachment : UseDraftTestimonyAttachment
67
68
} ) => {
69
+ const { t } = useTranslation ( "attachment" )
68
70
return (
69
71
< Form . Label >
70
- < span className = "me-1" >
71
- (Optional) Provide your testimony as a file attachment
72
- </ span >
72
+ < span className = "me-1" > { t ( "provide_testimony_as_file" ) } </ span >
73
73
{ status === "loading" && < Spinner animation = "border" size = "sm" /> }
74
74
{ status === "error" && (
75
75
< FontAwesomeIcon icon = { faExclamationTriangle } className = "text-danger" />
@@ -85,13 +85,10 @@ export const AttachmentLink = ({
85
85
attachment : AttachmentInfo
86
86
className ?: string
87
87
} ) => {
88
- const linkLabel = [
89
- "Attached" ,
90
- name ?? "Testimony" ,
91
- size ? formatSize ( size ) : null
92
- ]
93
- . filter ( Boolean )
94
- . join ( " - " )
88
+ const { t } = useTranslation ( "attachment" )
89
+ const linkLabelParts = [ t ( "attached" ) , name ?? t ( "testimony" ) ]
90
+ if ( size ) linkLabelParts . push ( formatSize ( size ) )
91
+ const linkLabel = linkLabelParts . join ( " - " )
95
92
return (
96
93
< External className = { className } href = { url } >
97
94
{ linkLabel }
@@ -106,13 +103,10 @@ const Attached = ({
106
103
attachment : UseDraftTestimonyAttachment
107
104
confirmRemove : boolean
108
105
} ) => {
106
+ const { t } = useTranslation ( "attachment" )
109
107
const { url, name, size, id, remove, status } = attachment
110
108
const onClick = ( ) => {
111
- if (
112
- ! confirmRemove ||
113
- confirm ( "Are you sure you want to remove your attachment?" )
114
- )
115
- remove ( )
109
+ if ( ! confirmRemove || confirm ( t ( "confirm_remove" ) ) ) remove ( )
116
110
}
117
111
return (
118
112
< Row className = "align-items-center" >
@@ -128,7 +122,7 @@ const Attached = ({
128
122
onClick = { onClick }
129
123
disabled = { status === "loading" }
130
124
>
131
- Remove
125
+ { t ( "remove" ) }
132
126
</ Button >
133
127
</ Col >
134
128
</ Row >
@@ -140,19 +134,18 @@ const StatusMessage = ({
140
134
} : {
141
135
attachment : UseDraftTestimonyAttachment
142
136
} ) => {
137
+ const { t } = useTranslation ( "attachment" )
143
138
if ( status === "error" ) {
144
139
let message : string
145
140
if ( error ?. code === "storage/unauthorized" ) {
146
- message = "Invalid file. Please upload PDF's less than 10 MB"
141
+ message = t ( "error.storage_unauthorized" )
147
142
} else {
148
- message = "Something went wrong. Please try again."
143
+ message = t ( "error.generic" )
149
144
}
150
145
151
146
return < Form . Text className = "text-danger" > { message } </ Form . Text >
152
147
} else if ( status === "ok" && ! id ) {
153
- return (
154
- < Form . Text > Files must be PDF documents and less than 10 MB.</ Form . Text >
155
- )
148
+ return < Form . Text > { t ( "file_requirements" ) } </ Form . Text >
156
149
} else {
157
150
return null
158
151
}
0 commit comments