File size: 1,581 Bytes
56b6519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { PencilSquareIcon } from '@heroicons/react/24/outline';
import { t } from 'i18next';
import React, { ReactElement } from 'react';

import PrimaryButton from '../button/PrimaryButton';

type EditCardProps = {
  title: string;
  editTitle: string;
  children: ReactElement;
  isEditing: boolean;
  onClickEdit: () => void;
  onClickSave: () => void;
  onClickCancel: () => void;
};

const EditCard: React.FC<EditCardProps> = ({
  title,
  editTitle,
  children,
  isEditing,
  onClickEdit,
  onClickSave,
  onClickCancel,
}) => {
  return (
    <div className="border rounded-lg bg-gray-900">
      <div className="flex justify-between py-3 mx-4">
        {!isEditing ? (
          <>
            <h2 className="text-xl font-semibold">{title}</h2>
            <button onClick={onClickEdit} type="button">
              <PencilSquareIcon className="py-1 size-10" />
            </button>
          </>
        ) : (
          <h2 className="text-xl pb-3 font-semibold">{editTitle}</h2>
        )}
      </div>
      <hr className="h-1 mx-4 bg-gray-600 border-0 rounded" />
      <div className="p-2">{children}</div>
      {isEditing ? (
        <div>
          <hr className="h-1 mx-4 bg-gray-600 border-0 rounded" />
          <div className="flex items-end space-x-4 m-4">
            <PrimaryButton color="gray" onClick={onClickCancel}>
              {t('btn.cancel')}
            </PrimaryButton>
            <PrimaryButton onClick={onClickSave}>{t('btn.save')}</PrimaryButton>
          </div>
        </div>
      ) : null}
    </div>
  );
};

export default EditCard;