File size: 7,758 Bytes
d97b8f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import React from 'react';
import { format } from 'date-fns';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { User, Calendar, CheckCircle, XCircle, AlertTriangle, MessageSquare } from 'lucide-react';
import { AssetRequestWithAvailability } from '@/types/asset-request';

interface ViewDetailsDialogProps {
  isOpen: boolean;
  onClose: () => void;
  request: AssetRequestWithAvailability | null;
  onApprove?: (request: AssetRequestWithAvailability) => void;
  onReject?: (request: AssetRequestWithAvailability) => void;
  onAddComment?: (request: AssetRequestWithAvailability) => void;
}

const ViewDetailsDialog: React.FC<ViewDetailsDialogProps> = ({

  isOpen,

  onClose,

  request,

  onApprove,

  onReject,

  onAddComment,

}) => {
  const handleOverlayClick = (e: React.MouseEvent) => {
    if (e.target === e.currentTarget) {
      onClose();
    }
  };

  const getAvailabilityBadge = (available: number, requested: number) => {
    if (available >= requested) {
      return (
        <Badge className="bg-green-100 text-green-800 border-green-200">

          Available ({available})

        </Badge>
      );
    } else if (available > 0) {
      return (
        <Badge className="bg-yellow-100 text-yellow-800 border-yellow-200">

          <AlertTriangle className="h-3 w-3 mr-1 inline" />

          Partial ({available}/{requested})

        </Badge>
      );
    } else {
      return (
        <Badge className="bg-red-100 text-red-800 border-red-200">

          <XCircle className="h-3 w-3 mr-1 inline" />

          Unavailable

        </Badge>
      );
    }
  };

  if (!isOpen || !request) return null;

  return (
    <div 

      className="fixed inset-0 z-[999] flex items-center justify-center p-4 overflow-y-auto"

      role="dialog"

      aria-modal="true"

      aria-labelledby="dialog-title"

    >

      {/* Overlay */}

      <div 

        className="fixed inset-0 bg-black/80 backdrop-blur-sm transition-opacity"

        onClick={handleOverlayClick}

        aria-hidden="true"

      />

      

      {/* Modal Content */}

      <div 

        className="relative z-[1000] w-full max-w-2xl rounded-lg border bg-background shadow-lg animate-in fade-in-0 zoom-in-95 duration-200 max-h-[90vh] overflow-hidden flex flex-col"

        onClick={(e) => e.stopPropagation()}

      >

        {/* Header */}

        <div className="p-6 border-b flex-shrink-0">

          <h2 

            id="dialog-title" 

            className="text-lg font-semibold text-foreground"

          >

            Request #{request.requestID} Details

          </h2>

          <p className="text-sm text-muted-foreground mt-1">

            Review the complete details of this asset request

          </p>

        </div>

        

        {/* Content - Scrollable */}

        <div className="p-6 space-y-4 overflow-y-auto flex-1">

          {/* Employee and Date Info */}

          <div className="grid grid-cols-2 gap-4">

            <div>

              <div className="text-sm font-medium text-muted-foreground mb-1">

                Employee

              </div>

              <div className="flex items-center gap-2">

                <User className="h-4 w-4" />

                <span>{request.employeeName}</span>

              </div>

            </div>

            <div>

              <div className="text-sm font-medium text-muted-foreground mb-1">

                Submitted Date

              </div>

              <div className="flex items-center gap-2">

                <Calendar className="h-4 w-4" />

                <span>

                  {format(new Date(request.submittedDate), 'PPP')}

                </span>

              </div>

            </div>

          </div>



          {/* Requested Assets */}

          <div>

            <div className="text-sm font-medium text-muted-foreground mb-2">

              Requested Assets

            </div>

            <div className="space-y-2">

              {request.requestedAssets.map((asset, idx) => (

                <Card key={idx} className="border-2">

                  <CardContent className="p-3">

                    <div className="flex items-start justify-between gap-3">

                      <div className="flex-1 min-w-0">

                        <div className="font-medium">{asset.assetType}</div>

                        <div className="text-sm text-muted-foreground">

                          Quantity: {asset.quantity}

                        </div>

                        {asset.specifications && (

                          <div className="text-sm text-muted-foreground mt-1">

                            Specs: {asset.specifications}

                          </div>

                        )}

                      </div>

                      <div className="flex-shrink-0">

                        {request.availabilityStatus[idx] &&

                          getAvailabilityBadge(

                            request.availabilityStatus[idx].available,

                            request.availabilityStatus[idx].requested

                          )}

                      </div>

                    </div>

                  </CardContent>

                </Card>

              ))}

            </div>

          </div>



          {/* Justification */}

          <div>

            <div className="text-sm font-medium text-muted-foreground mb-2">

              Justification

            </div>

            <div className="bg-muted/50 rounded-md p-3 text-sm">

              {request.justification}

            </div>

          </div>

        </div>



        {/* Footer - Fixed at bottom */}

        <div className="p-6 border-t bg-muted/30 flex-shrink-0">

          <div className="flex justify-between items-center gap-3">

            <div>

              {onAddComment && (

                <Button

                  type="button"

                  variant="outline"

                  onClick={() => {

                    onClose();

                    onAddComment(request);

                  }}

                  className="border-blue-600 text-blue-600 hover:bg-blue-50"

                >

                  <MessageSquare className="h-4 w-4 mr-2" />

                  Add Comment

                </Button>

              )}

            </div>

            <div className="flex gap-3">

              <Button 

                type="button"

                variant="outline" 

                onClick={onClose}

              >

                Close

              </Button>

              {onApprove && (

                <Button

                  type="button"

                  variant="default"

                  onClick={() => {

                    onClose();

                    onApprove(request);

                  }}

                  className="bg-green-600 hover:bg-green-700 text-white"

                >

                  <CheckCircle className="h-4 w-4 mr-2" />

                  Approve

                </Button>

              )}

              {onReject && (

                <Button

                  type="button"

                  variant="destructive"

                  onClick={() => {

                    onClose();

                    onReject(request);

                  }}

                >

                  <XCircle className="h-4 w-4 mr-2" />

                  Reject

                </Button>

              )}

            </div>

          </div>

        </div>

      </div>

    </div>
  );
};

export default ViewDetailsDialog;